Rich Text controls

Source: Internet
Author: User

A variety of rich text control on the network total feel and specific items are not too, so I wrote a rich text control, is written with Coretext. Now open up for everyone to learn from and use. I have written some basic functions that you can easily add to the functionality you want to implement.

You can arbitrarily use, modify, extend this control, please do not delete the author information

When you use it, don't forget to introduce the Coretext library.

Demo effect


Call the method code as follows:

1. Display pictures

-(void) showimage{uifont *font = [Uifont systemfontofsize:17];    Sjrichtextview *richtextview = [[Sjrichtextview alloc] Initwithframe:cgrectmake (100, 50, 200, 80)];    Richtextview.textmaxwidth = 150;    Richtextview.textcolor = [Uicolor blackcolor];    Richtextview.font = font;    NSString *imagetext = [Sjrichtextinterpreter imgtextwithurl:@ "Demoimage.png" Size:cgsizemake (50, 50)];    Richtextview.text = [NSString stringwithformat:@ "Photo Demo:%@", Imagetext]; [Self.view Addsubview:richtextview];}

2. Display text (supports calculating height by number of rows and calculating total text height)

-  (void) showtext{    uifont *font = [uifont systemfontofsize:17];     SJRichTextView *richTextView = [[SJRichTextView alloc]  Initwithframe:cgrectmake (100, 150, 200, 71)];    richtextview.textmaxwidth  = 150;    richTextView.textColor = [UIColor blackColor];     richtextview.font = font;    richtextview.text = @ " Text presentation text presentation text presentation text presentation text presentation text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo text Demo;     [self.view addsubview:richtextview];        cgfloat  minheight = [richtextview heightforlinenumber:4];    nslog (@ " The height of four lines of text is:%f ",  minheight);         cgfloat maxheight =  [richtextview heightformaxLine];    nslog (@ "Total text height is:%f",  maxheight);} 

3. Display expression

-  (void) showemotion{    uifont *font = [uifont systemfontofsize :17];    sjrichtextview *richtextview = [[sjrichtextview alloc]  Initwithframe:cgrectmake (100, 300, 200, 80)];    richtextview.textmaxwidth  = 150;    richTextView.textColor = [UIColor redColor];     richtextview.font = font;    richtextview.emotioniconwidth  = font.lineHeight;    richTextView.emotionIconHeight =  font.lineheight;    richtextview.richtextviewdatasource = self;     richtextview.text = @ "Expression presentation: [Aesthetic]";     [self.view addsubview: Richtextview];} #pragma  mark SJRichTextViewDataSource-  (nsstring *) imagepathwithemotionstring: (nsstring  *) emotionstring{    if  ([emotionstring isequaltostring:@, "aesthetic"])  {         nsstring *imagepath = [nsstring stringwithformat:@ "%@/%@",  [NSBundle  mainbundle].resourcepath, @ "Demoimage.png"];        return  imagepath;    }    return nil;}

4. Show Link

-  (void) showurl{    uifont *font = [uifont systemfontofsize:15];     SJRichTextView *richTextView = [[SJRichTextView alloc]  Initwithframe:cgrectmake (50, 400, 300, 80)];    richtextview.textmaxwidth  = 300;    richTextView.textColor = [UIColor redColor];     richtextview.font = font;    richtextview.richtextviewdelete  = self;    NSString *urlText = [SJRichTextInterpreter  urltextwithurl:@ "http://www.baidu.com"  displaystring:@ "Baidu"];    richtextview.text  = [nsstring stringwithformat:@ "The text on the right is a link, point to see:%@",  urltext];    [ Self.view addsubview:richtextview];} #pragma  mark SJRichTextViewDelegate-  (void) Touchurl: (nsstring *) URL{   &NBSp nsurl *gourl = [nsurl urlwithstring:url];    if  (goURL ==  nil)  {        return;    }     [[uiapplication sharedapplication] openurl:gourl];}

Demo Project: http://pan.baidu.com/share/home?uk=4012188959#category/type=0

Rich Text controls

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.