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