How can you bold just one word in a UILabel?

后端 未结 3 980
忘了有多久
忘了有多久 2021-02-15 16:09

It\'s easy to display a single label with entirely the same text but what happens when you want to display one word in bold?

Example:

All your bases are<

3条回答
  •  攒了一身酷
    2021-02-15 16:59

    As Evan Mulawski wrote, UILabel won't get you what you want. For that matter, neither will UITextField nor UITextView.

    Another approach would be to subclass UIView and write a -drawRect: method that does what you want. You might look at

    • CGContextShowTextAtPoint
    • [NSString drawAtPoint:withFont:]
    • [NSString sizeWithFont:]

    If you won't be requiring a lot of line breaks and wrapping, then you could probably craft something fairly easily.

    UIWebView would probably be faster but it seems like a lot of overhead for something as simple as a styled label.

提交回复
热议问题