IOS Simple Graphics Mixed 01

Source: Internet
Author: User

1. Display the picture in the label

Graphic mixed display-(void) setlabel{//nstextattachment-attachment nstextattachment *attachment = [[Nstextattachment alloc] init];//set for attachment Picture Attachment.image = [UIImage imagenamed: @ "D_aini"];//key attachment added to text mix nsattributedstring *str = [nsattributedstring attributedstringwithattachment:attachment];//set the label content Self.label.backgroundColor = [Uicolor Graycolor]; Self.label.attributedText = str;}

Show effect



2. Set the display image size

Graphic control picture size-(void) setlabel2{//nstextattachment-Accessories nstextattachment *attachment = [[Nstextattachment alloc] init];// Set Picture Attachment.image = [UIImage imagenamed: @ "D_aini"];//set Picture size//Picture is a square, usually with the text size of the picture size is the same as the text height, not the same as the label height cgfloat Height = Self.label.font.lineheight;attachment.bounds = CGRectMake (0, 0, height, height);//Add nsattributedstring *str = [ Nsattributedstring attributedstringwithattachment:attachment];//Set the label content Self.label.backgroundColor = [Uicolor Graycolor];self.label.attributedtext = str;}

Show effect


3. Insert Picture in text

Text Image stitching Display-(void) setlabel3{//nstextattachment-Accessories//1. Create a text attachment containing a picture, know the attachment boundsnstextattachment *attachment = [[ Nstextattachment Alloc] init];//Set Picture attachment.image = [UIImage imagenamed: @ "D_aini"];//set size cgfloat height = Self.labe L.font.lineheight;attachment.bounds = CGRectMake (0, 0, height, height);//Add//2. Create a property string using an attachment nsattributedstring * attrstring = [nsattributedstring attributedstringwithattachment:attachment];//stitching text NSString *str = @ "M";//3. Creating variable Characters Stitching string Nsmutableattributedstring *STRM = [[Nsmutableattributedstring alloc] initwithstring:str]; [StrM appendattributedstring:attrstring]; [StrM appendattributedstring: [[Nsattributedstring alloc] initwithstring: @ "Every day"]];//set label Content Self.label.backgroundColor = [Uicolor graycolor];self.label.attributedtext = StrM;}

Show effect



IOS Simple Graphics Mixed 01

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.