2013-12-19 4 views
0

Я хочу, чтобы установить название кнопки с подчеркиванием и browncolor:Кнопка Цвет заголовка

За то, что я делаю:

NSMutableAttributedString *nearestLocation = [[NSMutableAttributedString alloc] initWithString:@"Locate Manually"]; 
[nearestLocation addAttribute:(NSString*)kCTUnderlineStyleAttributeName 
        value:[NSNumber numberWithInt:NSUnderlineStyleSingle] 
        range:(NSRange){0,[nearestLocation length]}]; 
[btn_manually setAttributedTitle:nearestLocation forState:UIControlStateNormal]; 
[btn_manually setTitleColor:[UIColor brownColor] forState:UIControlStateNormal]; 

Он отображает подчеркивание, но не browncolor.

+0

Вам нужно установить цвет, используя NSMutableAttributedString как ваш подчеркивание логики. –

ответ

1

Попробуйте использовать, как это ....

[nearestLocation addAttribute:NSForegroundColorAttributeName value:[UIColor brownColor] range:NSMakeRange(0,[nearestLocation length])]; 
1

В прошивке, NSAttributedString используется изменением текста, вы можете использовать «NSMutableAttributedString» для мульти цветного текста, шрифта, стиля и т.д. с помощью одного или UIButton UILabel.

NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:@"The Underlined text"]; 

// making text property to underline text- 
[titleString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, [titleString length])]; 

// using text on button 
[btn_manually setAttributedTitle: titleString forState:UIControlStateNormal]; 
btn_manually.titleLabel.textColor = [UIColor brownColor]; 
0
NSString *[email protected]"your string"; 
    NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:tempString];                      
    int lenght=(int)[tempString length]; 
    [attString addAttribute:(id)NSForegroundColorAttributeName value:[UIColor brownColor] range:NSMakeRange(0,lenght)]; 
    [attString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:2] range:NSMakeRange(0, length)]; 

    UIButton *hyperLinkButton=[UIButton buttonWithType:UIButtonTypeCustom]; 
    hyperLinkButton.frame=CGRectMake(30, 5, 100, 30); 
    [hyperLinkButton setAttributedTitle:attString forState:UIControlStateNormal]; 
    hyperLinkButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 
    hyperLinkButton.tag=[[[[[[personalDetailDictionary objectForKey:@"Acknowledgements"] objectForKey:@"details"] objectAtIndex:i] objectForKey:@"tagValue"] objectForKey:@"text"] intValue]; 
    [hyperLinkButton addTarget:self action:@selector(hyperLinkAction:) forControlEvents:UIControlEventTouchUpInside]; 
    hyperLinkButton.titleLabel.textAlignment=NSTextAlignmentLeft; 
    [self.view addSubview:hyperLinkButton]; 
Смежные вопросы