Hi there,
Because Xcode crashes when clicking in IB TextView after selecting "attributed", I need to know how to get parts of text in different styles and sizes, for example:
This should be in Helvetica bold 13 and this should be in Helvetica normal 11
How can I do that in code (Objective-c) ?
Thanks in advance for any advice
Here is how you would do in Swift, tested. Conversion to objc should be straightforward.
If the textView is: "This should be in Helvetica bold 13 and this should be in Helvetica normal 11"
let attributedText = NSMutableAttributedString(attributedString: textView.attributedText!)
// Use NSString so the result of rangeOfString is an NSRange.
let text = textView.text! as NSString
// Find the range of each element to modify.
let boldRange = text.range(of: "This should be in Helvetica bold 13")
let boldFont = UIFont(name: "Helvetica-bold", size: 13.0) as Any
// Handle bold
attributedText.addAttribute(NSAttributedString.Key.font, value: boldFont, range: boldRange)
// Handle small.
let smallRange = text.range(of: "and this should be in Helvetica normal 11")
let smallFont = UIFont(name: "Helvetica", size: 11.0) as Any
attributedText.addAttribute(NSAttributedString.Key.font, value: smallFont, range: smallRange)
textView.attributedText = attributedText