I added one UIButton to my UITableView programmatically. My problem is that I need to give Letter Spacing and also change the color of the button name. I gave the Letter Spacing text in the button title using the code below, but the color of the title text does not change.
here is my code:
btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect]; btnLogin.frame = CGRectMake(0, 0, 320, 42); btnLogin.titleLabel.font = customFont; NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"LOG IN"]; [attributedString addAttribute:NSKernAttributeName value:@(spacing) range:NSMakeRange(0, [@"LOG IN" length])]; [btnLogin setAttributedTitle:attributedString forState:UIControlStateNormal]; btnLogin.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_highlighted.png"]]; [btnLogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
Could you help me change the color of the button name here? Thank.
iphone ios7 uibutton nsattributedstring
Anand Gautam Jul 02 '14 at 7:26 2014-07-02 07:26
source share