Hello Friends,
NSMutableAttributedString allows to set different attributes(font size,font color) for different parts of the string.
To use NSMutableString you may use the following code:
//Create an object of NSMutableAttrinbuteString and assign it with the complete string
NSMutableAttributedString *stringToSet = [[NSMutableAttributedString alloc]initWithString:@"your string goes here"];
//To set different font Color
[stringToSet addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,10)]; //User Defined Range
[stringToSet addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(10,20)]; // User Defined Range
//To set different font Style
[stringToSet addAttribute:NSFontAttributeName value: [UIFont fontWithName:@"Roboto-Regular" size:15.0] range:NSMakeRange(0,10)];
[stringToSet addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Roboto-Light" size:14.0] range:NSMakeRange(10,20)];
To set this attributed string on label you will have to use attributedText property of label and set as follows:
userLbl.setAttributedText = stringToSet;
0 Comment(s)