Bold & Non-Bold Text in a Single Uilabel

Partially Bold Text in UILabel

If you just want the names to appear in bold, use the UILabel attributedText attribute to set an attributed string instead of a plain text string.

Something like:

let name = names[indexPath.row]
let color = colors[indexPath.row]
let attributedText = NSMutableAttributedString(string: name, attributes:[NSFontAttributeName : UIFont.boldSystemFont(ofSize:15)])
attributedText.append(NSAttributedString(string:color))
cell.info.attributedText = attributedText

Of course, you'd need to set the font in the above for the bold part according to how you have the cell styled.

How to format some text as bold within a UILabel?

Use the attributedText property:

NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"This is a test."];
[text addAttribute:NSFontAttributeName
value:[UIFont boldSystemFontOfSize:12]
range:NSMakeRange(0, 4)];
label.attributedText = text;

Swift: Programmatically make UILabel bold without changing its size?

Why not just:

titleLabel.font = UIFont.boldSystemFont(ofSize: titleLabel.font.pointSize)

How do I remove bold from a UILabel text in Objective-C?

You can use the systemFontOfSize method on UIFont.

cell.title.font=[UIFont systemFontOfSize:self.textFontSize];

Setting UILabel to bold?

Have you added the Custom Font to your project? If not you can do so by following this link to Apple's documentation : Adding a Custom Font to your App

You have to make sure the font file is a target member of your app; otherwise, the font file will not be distributed as part of your app.

To find the font names available to your app, do this:

for family in UIFont.familyNames.sorted() {
let names = UIFont.fontNames(forFamilyName: family)
print("Family: \(family) Font names: \(names)")
}


Related Topics



Leave a reply



Submit