iOS Rich Text instance

Source: Internet
Author: User

:

Code:

#import "ViewController.h"

@interface Viewcontroller ()

@end

@implementation Viewcontroller

-(void) Viewdidload {

[Super Viewdidload];

UILabel *lab = [[UILabel alloc] Initwithframe:cgrectmake (10, 20, 300, 50)];

Lab.numberoflines = 0;

Lab.text = @ " The dim and hazy: Suddenly the return of the pizza can be a classic money to lose weight of the classics scattered points redemption can be comfortable places to take a holiday ah, we think the barber shop said is Curry Futing a happy to sprinkle into the bomb shelter hot and sour powder to understand the sprinkle fertilizer Danjiangkou ah, we look at the environment of Satan spread out of Caesar's coffee shop in the air, 。 ";

Lab.font = [Uifont systemfontofsize:10];

Nsrange range = [Lab.text rangeofstring:@ ":"];

[Self.view Addsubview:lab];

nsmutableattributedstring *att = [[Nsmutableattributedstring alloc] initWithString:lab.text];

[Att addattributes:@{nsforegroundcolorattributename:[uicolor redcolor]} range:nsmakerange (0, range.location+1)];

Lab.attributedtext = att;

UILabel *LAB1 = [[UILabel alloc] Initwithframe:cgrectmake (10, 80, 300, 20)];

Lab1.text = @ "Bounce is away from the reply stars Light chase:" Good silly You ";

Lab1.font = [Uifont systemfontofsize:10];

[Self.view ADDSUBVIEW:LAB1];

Nsrange Range1 = [Lab1.text rangeofstring:@ "reply"];

Nsrange range2 = [Lab1.text rangeofstring:@ ":"];

nsmutableattributedstring *att1 = [[Nsmutableattributedstring alloc] initWithString:lab1.text];

[Att1 addattributes:@{nsforegroundcolorattributename:[uicolor Redcolor]} range:nsmakerange (0, range1.location)];

[Att1 addattributes:@{nsforegroundcolorattributename:[uicolor Redcolor]} range:nsmakerange (range1.location+2, Range2.location-range1.location-1)];

NSLog (@ "%d%d", range1.location,range2.location);

Lab1.attributedtext = ATT1;

}

@end

iOS Rich Text instance

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.