make UILabel's text bold

2019-03-08 13:24发布

I want to make UILabel's text bold

infoLabel=[[UILabel alloc]initWithFrame:CGRectMake(90,150, 200, 30)];
[infoLabel setText:@"Drag 14 more Flavors"];
[infoLabel setBackgroundColor:[UIColor clearColor]];
[infoLabel setFont:[UIFont fontWithName:@"Arial" size:16]];

[infoLabel setTextColor:[UIColor colorWithRed:193.0/255 
                                        green:27.0/255 
                                         blue:23.0/255 
                                        alpha:1 ]];

5条回答
混吃等死
2楼-- · 2019-03-08 13:28

Try

[infoLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:16]];

It may also be worth checking if the font you're trying to use is available on device

查看更多
小情绪 Triste *
3楼-- · 2019-03-08 13:37

Using the GUI in Xcode select the label then go to the Attributes Inspector. One of the options is Font. Click on the font icon (not the up-down arrows). In the popup that appears expand the Font ComboxBox. Under the Bold System section choose Regular.

Xcode screenshot

查看更多
唯我独甜
4楼-- · 2019-03-08 13:43

If you want to retain the system font and make it bold:

[infoLabel setFont:[UIFont boldSystemFontOfSize:16]];
查看更多
走好不送
5楼-- · 2019-03-08 13:50

You can set the stroke with a negative value to make a bold effect if you don't have the bold variation of your custom font. See here:

How can I both stroke and fill with NSAttributedString w/ UILabel

查看更多
Melony?
6楼-- · 2019-03-08 13:55

For swift users this should work:

myLabel.font = UIFont.boldSystemFont(ofSize: 12.0)

or if you'd like to use a different font:

myLabel.font = UIFont(name:"HelveticaNeue-Bold", size: 12.0)
查看更多
登录 后发表回答