I want to set title on Button in two colors.
Is it possible same as given image below ?
Any help will be appreciated.
Thanks in advance.
This is what you need
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(5,10,300,20);
[self.view addSubview:btn];
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"100 Photos"]];
[attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 3)];
[btn setAttributedTitle:attrStr forState:UIControlStateNormal];
In storyBoard : Follow the ScreenShot.
For Programmatically : There are already many answers posts over here for attributed text and If you want to put BackgroundImage for UIButton Set a button background image iPhone programmatically
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With