make UILabel's text bold

IosObjective CUilabelUifontTextcolor

Ios Problem Overview


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

Ios Solutions


Solution 1 - Ios

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

[infoLabel setFont:[UIFont boldSystemFontOfSize:16]];

Solution 2 - Ios

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

Solution 3 - Ios

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

Solution 4 - Ios

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)

Solution 5 - Ios

Where possible I would suggest using dynamic font sizes to provide the best possible accessibility to your users.

You can make a label use a system dynamic font and set it to have bold text by doing the following:

 exampleLabel.font = UIFont.preferredFont(forTextStyle: .body, compatibleWith: UITraitCollection(legibilityWeight: .bold))

Solution 6 - Ios

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:

https://stackoverflow.com/questions/16047901/how-can-i-both-stroke-and-fill-with-nsattributedstring-w-uilabel

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAliView Question on Stackoverflow
Solution 1 - IosMannyView Answer on Stackoverflow
Solution 2 - IosVladimirView Answer on Stackoverflow
Solution 3 - IosChad KuehnView Answer on Stackoverflow
Solution 4 - IosNyakibaView Answer on Stackoverflow
Solution 5 - IosEdwardView Answer on Stackoverflow
Solution 6 - IosFerran MaylinchView Answer on Stackoverflow