একটি UILabel-এ বোল্ড (Bold) এবং নন-বোল্ড (Regular) টেক্সট একসাথে ব্যবহার করা যায় দুটি পদ্ধতিতে — স্টোরিবোর্ড থেকে বা প্রোগ্রাম্যাটিক্যালি।
পদ্ধতি ১: স্টোরিবোর্ড থেকে এডিট
- লেবেল সিলেক্ট করুন, Attribute Inspector-এ যান।
- Text-এ "Plain"-এর বদলে "Attributed" সিলেক্ট করুন।
- লিখুন: Bold Regular
- "Bold" শব্দটি সিলেক্ট করুন, রাইট ক্লিক → Font → Bold সিলেক্ট করুন।
পদ্ধতি ২: প্রোগ্রাম্যাটিক্যালি (NSAttributedString)
override func viewDidLoad() {
super.viewDidLoad()
let boldAttribute: [NSAttributedString.Key: Any] = [
.font: UIFont(name: "HelveticaNeue-Bold", size: 18.0)!
]
let regularAttribute: [NSAttributedString.Key: Any] = [
.font: UIFont(name: "HelveticaNeue-Light", size: 18.0)!
]
let boldText = NSAttributedString(string: "Bold", attributes: boldAttribute)
let regularText = NSAttributedString(string: " regular", attributes: regularAttribute)
let newString = NSMutableAttributedString()
newString.append(boldText)
newString.append(regularText)
lbl.attributedText = newString
}
উপরের যেকোনো পদ্ধতি ফলো করলে নিচের ফলাফল मिलবে।
