NSMutableAttributedString *myString = [[NSMutableAttributedString alloc] initWithString:@"ABCDEFGHIJKLMNOPQRSTUV"];
[myString addAttribute:NSForegroundColorAttributeName value: [UIColor blueColor] range:NSMakeRange(0,2)];
[myString addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:NSMakeRange(2,2)];
[myString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:3.0] range:NSMakeRange(2, 2)];
[myString addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:NSMakeRange(4,2)];
[myString addAttribute:NSStrokeWidthAttributeName value:[NSNumber numberWithFloat:-3.0] range:NSMakeRange(4, 2)];
NSShadow *shadowDic=[[NSShadow alloc] init];
[shadowDic setShadowBlurRadius:2.0];
[shadowDic setShadowColor:[UIColor brownColor]];
[shadowDic setShadowOffset:CGSizeMake(0, 3)];
[myString addAttribute:NSForegroundColorAttributeName value: [UIColor redColor] range:NSMakeRange(6,2)];
[myString addAttribute:NSShadowAttributeName value:shadowDic range:NSMakeRange(6,2)];
[myString addAttribute:NSForegroundColorAttributeName value: [UIColor orangeColor] range:NSMakeRange(8,2)];
[myString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(8,2)];
[myString addAttribute:NSForegroundColorAttributeName value: [UIColor purpleColor] range:NSMakeRange(10,2)];
[myString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleDouble] range:NSMakeRange(10,2)];
[myString addAttribute:NSForegroundColorAttributeName value: [UIColor magentaColor] range:NSMakeRange(12,2)];
[myString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleThick] range:NSMakeRange(12,2)];
[myString addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:NSMakeRange(14,2)];
[myString addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(14,2)];
[myString addAttribute:NSForegroundColorAttributeName value: [UIColor purpleColor] range:NSMakeRange(16,2)];
[myString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(16,2)];
[myString addAttribute:NSForegroundColorAttributeName value: [UIColor orangeColor] range:NSMakeRange(18,2)];
[myString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:2] range:NSMakeRange(18,2)];
[myString addAttribute:NSForegroundColorAttributeName value: [UIColor redColor] range:NSMakeRange(20,2)];
[myString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:3] range:NSMakeRange(20,2)];
self.label.attributedText = myString;
Wednesday, 22 January 2014
Different Types of Attributed Text ( NSAttributedString )
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment