Ios-swift3 Rich Text (uilable text graphics mixed)

Source: Internet
Author: User

Reprint Annotated Source: http://blog.csdn.net/qxuewei/article/details/53213636
Introduce the common Runecloth and graphics in iOS development
Requirements: Chu Cowei is big handsome (add a smiley picture) Chu Cowei: Red background Green font bold display is: Blue font 10th small font: Gray 42nd Font
Results shown in Uilabel:

Forgive me for the low-blown project name that I joked with my buddies.
Core code:

//Demand Chu Cowei is big handsome (add a smiley picture) Chu Cowei: Red background Green font bold display is: Blue font 10th small font handsome: Gray 42nd FontFileprivate func Fuwenbendemo () {//define Rich text as a formatted stringLet attributedstrm:nsmutableattributedstring = nsmutableattributedstring ()//Chu CoweiLet qiuxuewei:nsattributedstring = nsattributedstring (string:"Chu Cowei", Attributes: [Nsbackgroundcolorattributename:Uicolor. Red, Nsforegroundcolorattributename:Uicolor. Green, Nsfontattributename:Uifont. Boldsystemfont(Ofsize:28.0)])//(string: "Chu Cowei")        //YesLet shi:nsattributedstring = nsattributedstring (string:"Yes", Attributes: [Nsforegroundcolorattributename:Uicolor. Blue, Nsfontattributename:Uifont. Systemfont(Ofsize:10.0)])///StudLet dashuaige:nsattributedstring = nsattributedstring (string:"Handsome man.", Attributes: [Nsforegroundcolorattributename:Uicolor. Lightgray, Nsfontattributename:Uifont. Systemfont(Ofsize:42.0)])//Smiley pictureLet Smileimage:UIImage=UIImage(named:"D_hehe")! Let textattachment:nstextattachment = Nstextattachment () textattachment. Image= Smileimage Textattachment. Bounds=CGRect(x:0, Y:-4, Width: A, Height: A) ATTRIBUTEDSTRM. Append(Qiuxuewei) ATTRIBUTEDSTRM. Append(shi) attributedstrm. Append(Dashuaige) ATTRIBUTEDSTRM. Append(Nsattributedstring (attachment:textattachment)) label. Attributedtext= ATTRIBUTEDSTRM}

Complete Project Link: Https://git.oschina.net/qxuewei/AttributedStringDemo

Ios-swift3 Rich Text (uilable text graphics mixed)

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.