简体   繁体   中英

how to set different font size to text of button name in storyboard

I want to make application in which i want to make a login screen. It has button having name "Log inn with Facebook". I want font size of Facebook greater than Log in with. How can I set it in main storyboard?Can anyone plz help me?

Follow these steps-

1.Select button

2.Change its type to custom in Attributes inspector

3.Change its title from Plain to Attributed

4.Change the part of title which you want to be set bold

在此处输入图片说明

A solution would be to have a UIView with two different UILabel as subviews ( your "Log in with" label and your "Facebook" label ).

Then, above this UIView you could have a UIButton with a white background and an alpha equal to 0.01 so the button would be touchable but invisible.

This UIButton would be the functional part of your UI.

NSMutableAttributedString *titleText = [[NSMutableAttributedString alloc] initWithString:@"Login with Facebook"];
[yourbutton.titleLabel setFont:[UIFont boldSystemFontOfSize:14]];

// Set the font to bold from the beginning of the string to the ","
[titleText addAttributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:14] forKey:NSFontAttributeName] range:NSMakeRange(0, 10)];


// Set the attributed string as the buttons' title text
[yourbutton setAttributedTitle:titleText forState:UIControlStateNormal];

Instead of creating NSAttributedString create NSMutableAttributedString then you can just set the string like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM