UILabel font size?
Asked Answered
B

11

91

I can't seem to modify the font size of a UILabel with the following code:

itemTitle.font = [UIFont systemFontOfSize:25];

As i increase the number 25 to something greater, it seems to only add a top margin to the label, which consequently pushes the text down so much, so that the text gets cut off at the bottom or completely overflows.

i have another UILabel elsewhere with systemFontOfSize 25, and it's much smaller than the itemTitle text. What's going on? Isn't 25 supposed to be an absolute value?

i am so confused on how to programmatically change font size of uilabels.

Budgie answered 7/5, 2012 at 0:44 Comment(0)
G
56

Check that your labels aren't set to automatically resize. In IB, it's called "Autoshrink" and is right beside the font setting. Programmatically, it's called adjustsFontSizeToFitWidth.

Gosnell answered 7/5, 2012 at 1:0 Comment(0)
R
179

I have modified the UILabel by following code:

label.font=[label.font fontWithSize:25];

Try this and see whether is it working in your case or not???

Rutheruthenia answered 7/5, 2012 at 6:7 Comment(2)
label.font = label.font.fontWithSize(25) for SwiftRoncesvalles
Swift 3 label.font = label.font.withSize(25)Kp
G
56

Check that your labels aren't set to automatically resize. In IB, it's called "Autoshrink" and is right beside the font setting. Programmatically, it's called adjustsFontSizeToFitWidth.

Gosnell answered 7/5, 2012 at 1:0 Comment(0)
K
35
[label setFont:[UIFont systemFontOfSize:9]];

this works for me.

Kirven answered 18/3, 2013 at 9:59 Comment(0)
S
23

For Swift 3.1, Swift 4 and Swift 5, if you only want change the font size for a label :

let myLabel : UILabel = ...
myLabel.font = myLabel.font.withSize(25)
Syllogize answered 12/4, 2017 at 14:23 Comment(0)
P
12

**You can set font size by these properties **

timedisplayLabel= [[UILabel alloc]initWithFrame:CGRectMake(70, 194, 180, 60)];

[timedisplayLabel setTextAlignment:NSTextAlignmentLeft];

[timedisplayLabel setBackgroundColor:[UIColor clearColor]];

[timedisplayLabel setAdjustsFontSizeToFitWidth:YES];

[timedisplayLabel setTextColor:[UIColor blackColor]];

[timedisplayLabel setUserInteractionEnabled:NO];

[timedisplayLabel setFont:[UIFont fontWithName:@"digital-7" size:60]];

timedisplayLabel.layer.shadowColor =[[UIColor whiteColor ]CGColor ];

timedisplayLabel.layer.shadowOffset=(CGSizeMake(0, 0));

timedisplayLabel.layer.shadowOpacity=1;

timedisplayLabel.layer.shadowRadius=3.0;

timedisplayLabel.layer.masksToBounds=NO;

timedisplayLabel.shadowColor=[UIColor darkGrayColor];

timedisplayLabel.shadowOffset=CGSizeMake(0, 2);
Pursley answered 31/7, 2013 at 14:25 Comment(0)
H
7

This worked for me in

Swift 3

label.font = label.font.fontWithSize(40.0)

Swift 4

label.font = label.font.withSize(40.0)
Hocker answered 4/3, 2017 at 5:48 Comment(0)
S
5

very simple, yet effective method to adjust the size of label text progmatically :-

label.font=[UIFont fontWithName:@"Chalkduster" size:36];

:-)

Sikorski answered 10/12, 2013 at 11:39 Comment(0)
A
1

This worked for me:

sequencerPlayLabel.font = [UIFont fontWithName:kTypeFont size:kTypeFontSize];

-rich

Anguilla answered 17/4, 2014 at 14:48 Comment(0)
E
1

Answers above helped greatly.

Here is the Swift version.

@IBOutlet weak var priceLabel: UILabel!

*.... lines of code later*

self.priceLabel.font = self.priceLabel.font.fontWithSize(22)
Ephod answered 12/5, 2015 at 13:40 Comment(0)
H
1

In C# These ways you can Solve the problem, In UIkit these methods are available.

Label.Font = Label.Font.WithSize(5.0f);
       Or
Label.Font = UIFont.FromName("Copperplate", 10.0f);  
       Or
Label.Font = UIFont.WithSize(5.0f);
Hydrolyse answered 5/1, 2019 at 6:26 Comment(0)
C
-1

Try to change your label frame size height and width so your text not cut.

 [label setframe:CGRect(x,y,widht,height)];
Carlina answered 7/5, 2012 at 6:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.