0

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 ..

ios
  • 955
  • 1
  • 12
  • 35

1 Answers1

9

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;
}
Ilesh P
  • 3,940
  • 1
  • 24
  • 49