UITextView-এ একাধিক স্টাইল (রঙ, ফন্ট সাইজ) ব্যবহার করতে NSAttributedString ব্যবহার করুন।
let tx = UITextView()
tx.isScrollEnabled = true
tx.isUserInteractionEnabled = true
tx.frame = CGRect(x: 10, y: 25, width: self.view.frame.width, height: 100)
let attributeOne: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: 16),
.foregroundColor: UIColor.blue
]
let attributeTwo: [NSAttributedString.Key: Any] = [
.font: UIFont.systemFont(ofSize: 20),
.foregroundColor: UIColor.red
]
let string = NSAttributedString(string: "Text for first Attribute", attributes: attributeOne)
let string2 = NSAttributedString(string: "Text for first Attribute", attributes: attributeTwo)
let finalAttributedString = NSMutableAttributedString()
finalAttributedString.append(string)
finalAttributedString.append(string2)
tx.attributedText = finalAttributedString
self.view.addSubview(tx)
ফলাফল —
