ios - Determining the position of the end of the last line in UILabel -


this question has answer here:

the solution below works correctly names fit on 1 line

        cell.accessorytitlelabel.text = data.title         cell.accessorytitlelabel.sizetofit()         cell.discounticon.frame.origin.x = cell.accessorytitlelabel.frame.maxx + 7         cell.discounticon.hidden = discount == 0 

but need put discount icon @ end of last line: enter image description here

the best way insert image directly on label nstextattachment , resizing image per requirement, in way don't have calculate spacing , width.


swift 3 solution

var img_attachment = nstextattachment() img_attachment.image = uiimage(named: "name_of_image") img_attachment.bounds = cgrect(x: cgfloat(0), y: cgfloat(0), width: cgfloat(imgwidth), height:cgfloat(imgheight)) // can specify size , bounds of discount image var attributedstring = nsattributedstring(attachment: img_attachment) var lblstring = nsmutableattributedstring(string: "your text here") lblstring.append(attributedstring) cell.accessorytitlelabel.attributedtext = lblstring 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -