I have a string Ex: Arya said "We must find a solution" yesterday. Here I want to restrict the width of the text in bold ("We must find a solution") to 100, but others must not be shortened. So I added it as 3 different NSMutableAttributedString
s appended together and set this to a UILabel
. I want to know if I can restrict the width of one of these strings alone.
I tried the following :
let mutableString = "We must find a solution"
mutableString.draw(in: CGRect(x: 0, y: 0, width: 100, height: 30))
mutableString.draw(with: CGRect(x: 0, y: 0, width: 10, height: 10), options: .truncatesLastVisibleLine, context: .none)
mutableString.boundingRect(with: CGSize(width: 100, height: 40), options: [.truncatesLastVisibleLine,.usesFontLeading], context: .none)
But none of them worked. I want to reproduce the UILabel
.lineBreakMode = .byTruncatingTail
for a NSMutableAttributedString
. Am I doing something wrong here, is there a way to achieve this?