如何制作UIButton BOLD的一些文字

时间:2015-10-24 10:11:41

标签: ios objective-c uibutton

我想将我的UIButton标题设置为=== Don`t有一个帐户? 注册

如何制作一些大胆的文字。

    UIButton *signUpButton = [[UIButton alloc]initWithFrame:CGRectMake(40, 270, 240, 40)];
    [signUpButton setTitle:@"Don`t have an account? Sign Up" forState:UIControlStateNormal];
    [signUpButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    signUpButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [signUpButton setBackgroundColor:[UIColor clearColor]];
    [signUpButton addTarget:self action:@selector(signUpAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:signUpButton];

无法实现属性字符串..

1 个答案:

答案 0 :(得分:9)

在这里设置你的按钮文字......

[yourbutton setAttributedTitle:[self UnderLineTextString:strString]
        forState:UIControlStateNormal];

请尝试此功能......

-(NSMutableAttributedString *)UnderLineTextString:(NSString *)str
{
    NSMutableAttributedString *titleString = [[NSMutableAttributedString alloc] initWithString:str];

    [titleString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:20.0] range:NSMakeRange(0, [titleString length])];// set your text lenght..

    return titleString;
}