There is no problem with setting attributedstring at the end of uilabel...

Source: Internet
Author: User

Uilabel, we all know, will be shown at the end when the content is insufficient...

However, when you set attributedstring for uilabel, you will find that although the content is insufficient, the final...

This may be because the original setting of uilabel does not take effect after attributedstring is set (including font, font color, and other attributes)

If you want to display... manually set the truncation mode for uilabel

Nsmutableattributedstring * string = [[nsmutableattributedstring alloc] initwithstring: @ "one of London's landmark buildings is a bridge across the river, which was opened to traffic in 1984. the engine structure was used for bridge upgrading and downgrading. bridge Opening in order to let high ships pass through the scene wgqrgqwrfrgqwe "]; nsmutableparagraphstyle * Paragraph = [[nsmutableparagraphstyle alloc] init]; label. numberoflines = 0; // paragraph. linespacing = 20; // paragraph. paragraphspacing = 20; nsdictionary * attributes = @ {attributes: [uifont systemfontofsize: 17366f], attributes: paragraph}; [String addattributes: Attributes range: nsmakerange (0, String. length)]; [label setattributedtext: String]; label. linebreakmode = nslinebreakbytruncatingtail;

After attributedtext is set, setting linebreakmode will take effect. If attributedtext is re-set in the subsequent code, you need to re-set the linebreakmode. Otherwise, the linebreakmode of the label will be overwritten, no...

 

If you think the above method is troublesome, another solution is to use

Nsmutableparagraphstyle also has a linebreakmode which can be set to the truncation mode. This mode is directly added to attributedstring, so you do not need to set the linebreakmode of uilabel.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.