Benefits of NSAttributedString after iOS6

Source: Internet
Author: User

Benefits of NSAttributedString after iOS6

@ NSMutableAttributedString must be imported before iOS6: CoreText. framework, but it is not required after iOS6.

-(Void) testOfNSMutableAttributedStringAndNSAttributedString {/***-(void) addAttribute :( NSString *) name value :( id) value range :( nsange) range; * main method: * name attribute name * value corresponding to the effect * range mapped to the range effect */# pragma mark test data 0 NSString * testString = @ "NSMutableAttributed --- 0 "; UILabel * testLabel = [[UILabel alloc] initWithFrame: CGRectMake (60,100,200, 40)]; NSMutableAttributedString * testAttriString = [[NSMutableAttributedString alloc] initWithString: testString]; // Add a strikethrough [testAttriString addattriename: NSStrikethroughStyleAttributeName value: [NSNumber numberWithInt: NSUnderlineStyleSingle] range: NSMakeRange (0, testAttriString. length)]; // Add the underline [testAttriString addAttribute: NSUnderlineStyleAttributeName value: [NSNumber numberWithInt: NSUnderlineStyleSingle] range: NSMakeRange (0, testAttriString. length)]; // set the text font and size [testAttriString addAttribute: NSFontAttributeName value: [UIFont fontWithName: @ "Helvetica-Bold" size: 15] range: NSMakeRange (0, testAttriString. length)]; // set the stroke width [testAttriString addAttribute: NSStrokeWidthAttributeName value: [NSNumber numberWithInt: NSUnderlineStyleDouble] range: NSMakeRange (0, testAttriString. length)]; // the background color of the label [testAttriString addattriename: NSBackgroundColorAttributeName value: [UIColor yellowColor] range: NSMakeRange (0, testAttriString. length)]; // No effect is detected currently ..... [testAttriString addattristring: NSVerticalGlyphFormAttributeName value: [NSNumber numberWithInt: 1] range: NSMakeRange (0, testAttriString. length)]; // text color on the label (which also affects the color of strikethrough and underline) [testAttriString addAttribute: NSForegroundColorAttributeName value: [UIColor redColor] range: NSMakeRange (0, testAttriString. length)]; testLabel. attributedText = testAttriString; # pragma mark test data 1 NSString * testString1 = @ "tags --- 1"; UILabel * testLabel1 = [[UILabel alloc] initWithFrame: CGRectMake (60,200,200, 40)]; NSMutableAttributedString * testAttriString1 = [[NSMutableAttributedString alloc] initWithString: testString1]; // color and underline of text content, the color of the strikethrough is different. // NSStrokeColorAttributeName has no effect. // It must be set with NSStrokeWidthAttributeName. [testAttriString1 addAttribute: required value: [NSNumber numberWithInt: Required] range: NSMakeRange, identifier)]; [testAttriString1 addattriange: Identifier value: [UIColor redColor] range: NSMakeRange (0, priority)]; [testAttriString1 addattriange: NSStrokeColorAttributeName value: [UIColor cyanColor] range: NSMakeRange (0, strong)]; [testAttriString1 addattriange: invalid value: [NSNumber numberWithInt: Unknown] range: NSMakeRange (0, testAttriString1.length)]; Signature = testAttriString1; # pragma mark Test Data 2 NSString * testString2 = @ "NSMutableAttributed --- 2"; UILabel * testLabel2 = [[UILabel alloc] initWithFrame: CGRectMake (60,300,200, 40)]; optional * testAttriString2 = [[effecalloc] initWithString: testString2]; // NSShadow * shadow = [[NSShadow alloc] init]; [shadow setShadowColor: [UIColor colorWithRed: 0.053 green: 0.088 blue: 0.205 alpha: 1.000]; [shadow setShadowBlurRadius: 4.0]; [shadow setShadowOffset: CGSizeMake (2, 2)]; [testAttriString2 addattrimake: NSShadowAttributeName value: shadow range: NSMakeRange (0, [testAttriString2 length])]; testLabel2.backgroundColor = [UIColor clearColor]; testLabel2.attributedText = testAttriString2; [self. view addSubview: testLabel]; [self. view addSubview: testLabel1]; [self. view addSubview: testLabel2];}


Related Article

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.