Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use NSMutableAttributedString

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 186
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: