ios
ios

Reputation: 975

How to make some text of UIButton BOLD

I want to set my UIButton title to === Don`t have an account? Sign Up

How to make some text Bold.

    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];

Not able to implement attributed strings ..

Upvotes: 0

Views: 3044

Answers (1)

Ilesh P
Ilesh P

Reputation: 4036

Set here your button text like this ...

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

Please try this function ...

-(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;
}

Upvotes: 9

Related Questions