ios - Determining the position of the end of the last line in UILabel -
this question has answer here:
- how embed small icon in uilabel 13 answers
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
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
Post a Comment