Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Inter letter spacing OR different color to words of text of UIButton , UILetter , UITextfield

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 130
    Comment on it

    Hi all,

    if you want to give inter letter spacing to any kind of text of button , label , textfields etc then you can follow this code.

    First make attributed string :-

    NSMutableAttributedString * title = [[NSMutableAttributedString alloc] initWithString:@"this is sample code to text this example"];
        [title addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0,22)];
        [title addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:NSMakeRange(22,18)];
        [title addAttribute:NSKernAttributeName value:@(2.0) range:NSMakeRange(0,title.length)];
    

    Now, assign attributed string to any object for example :-

    //For UILabel
    
    self.label.attributedText = title;
    
    //For UIButton
    
    [self.button setAttributedTitle:title forState:UIControlStateNormal];
    
    //for UITextField
    
    self.textField.attributedText = title;
    

 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: