I don't know how to set text inset into uilabel from uiimage in swift

67 Views Asked by At

I was written to code using NSMutableAttributedString() with UIImage() and String.

extension UILabel {    
    func attachImageLabel(string: String, image: UIImage?) {
        let attachment = NSTextAttachment()
        attachment.image = image

        let attachmentString = NSAttributedString(attachment: attachment)
        let attributedString = NSAttributedString(string: string)
        
        let contentString = NSMutableAttributedString(string: "")
        contentString.append(attachmentString)
        contentString.append(attributedString)
        self.attributedText = contentString
        self.backgroundColor = .yellow
    }
}

But I want to write like below picture. Text must be move to top in UILabel.

enter image description here

0

There are 0 best solutions below