Formatted text in UILabel on iPhone

时间秒杀一切 提交于 2019-12-12 03:19:01

问题


Our requirement is to show some text bold and some text as normal style in a label.

e.g. ABC 002
(there is not space between ABC and 002)

There are lots of instances of such labels on a single view, so using UIWebView is not preferred.

Is it possible using the UILabel? If no, then what are the alternatives?


回答1:


Using normal UILabel dont think this is possible.

Check out this replacement for UILabel TTTAttributedLabel.

Another way is to use a CATextLayer with an NSAttributedString ! much lighter and simpler than 2 UILabels. (iOS 3.2 and above) as suggested here - Bold & Non-Bold Text In A Single UILabel?

Another way is to use 2 UILabels and position them correctly relative to each other Check out this topic from a previous Stack Overflow.




回答2:


For making the such labels you might have to use TTStyledTextLabel of Three20 libraries, which allows different styles on the same object of text.




回答3:


you can achieve that requirement using TTStyledTextLabel of three20 library



来源:https://stackoverflow.com/questions/9696097/formatted-text-in-uilabel-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!