Wednesday 25 June 2014

Attributed String With different Color and Italic

Hi  attributedString is introduced in ios 3.2 but However the ability to use them within certain UI controls such as UILabel, UIButton, UITextView, etc is only available since iOS6. I will discuss it here in this blog.

To give color attribute and italic effects in string you have to declare one  NSAttributedString like this :


#define MAINCOLOR [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0]


NSMutableAttributedString * Subtitlestring ;
[Subtitlestring addAttribute:NSForegroundColorAttributeName value:MAINCOLOR range:NSMakeRange(0,[strMovieName length])]; 

[Subtitlestring addAttribute:NSFontAttributeName value:[[Util sharedUtil] fontOfType:
@"HelveticaNeue-Italic bold:NO size:12 range:NSMakeRange(0,[Subtitlestring length])];
[lblSubtitle setAttributedText:Subtitlestring];

This will display gray  color  and italic string in label. 

Cheers!!!!