iOS TextView property settings

Source: Internet
Author: User

Uifontdescriptor *bodyfontdescriptor = [Uifontdescriptor preferredfontdescriptorwithtextstyle:uifonttextstylebody] ;
    Self.textView.font = [Uifont fontwithdescriptor:bodyfontdescriptor size:0];
    Self.textView.textColor = [Uicolor blackcolor];
    Self.textView.backgroundColor = [Uicolor Whitecolor];
    self.textView.scrollEnabled = YES;
    Let ' s modify some of the attributes of the attributed string.
    You can modify these attributes yourself to get a better feel for what they do.
    Note that the initial text was visible in the storyboard.
    nsmutableattributedstring *attributedtext = [[Nsmutableattributedstring alloc] initwithattributedstring: Self.textView.attributedText];
    NSString *text = Self.textView.text;
    Find the range of each element to modify.
    Nsrange Boldrange = [text rangeofstring:nslocalizedstring (@ "bold", nil)];
    Nsrange Highlightedrange = [text rangeofstring:nslocalizedstring (@ "highlighted", nil)];
    Nsrange Underlinedrange = [text rangeofstring:nslocalizedstring (@ "underlined", nil)];
    Nsrange Tintedrange = [text rangeofstring:nslocalizedstring (@ "tinted", nil)];
    Add Bold.
    Uifontdescriptor *boldfontdescriptor = [Self.textView.font.fontDescriptor fontdescriptorwithsymbolictraits: Uifontdescriptortraitbold];
    Uifont *boldfont = [Uifont fontwithdescriptor:boldfontdescriptor size:0];
    [Attributedtext addattribute:nsfontattributename Value:boldfont Range:boldrange];
    ADD highlight.
    [Attributedtext addattribute:nsbackgroundcolorattributename Value:[uicolor Aapl_applicationgreencolor] Range: Highlightedrange];
    Add underline.
    [Attributedtext addattribute:nsunderlinestyleattributename value:@ (nsunderlinestylesingle) Range:underlinedRange] ;
    ADD Tint.
    [Attributedtext addattribute:nsforegroundcolorattributename Value:[uicolor Aapl_applicationbluecolor] Range: Tintedrange];
    Add an image attachment.
    Nstextattachment *textattachment = [[Nstextattachment alloc] init];
    UIImage *image = [UIImage imagenamed:@ "Text_view_attachment"];
    Textattachment.image = image;
    Textattachment.bounds = CGRectMake (0, 0, image.size.width, image.size.height);
    nsattributedstring *textattachmentstring = [nsattributedstring attributedstringwithattachment:textattachment];
    [Attributedtext appendattributedstring:textattachmentstring];
    Self.textView.attributedText = Attributedtext;

iOS TextView property settings

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.