I have a UILabel coded programmatically. I want to change the size of the label when i pressed a button. how to change the size of that label? this is my code
UILabel *theLabel11 = [[UILabel alloc] initWithFrame:CGRectMake(0,0,100,30)];
[theLabel11 setText:@"US"];
[theLabel11 setTextAlignment:UITextAlignmentCenter];
[theLabel11 setFont: [UIFont fontWithName:@"Arial" size:13.0f]];
[theLabel11 setBackgroundColor:[UIColor orangeColor]];
[theLabel11 setTextColor:[UIColor blackColor]];
[scroll1 addSubview:theLabel11];
To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.
Changing the Xcode Font SizePress CMD + , Go to Font & Colors. Make sure to press CMD+A to select all possible text types. Then change the font size from the picker above.
The function [UIFont systemFontOfSize:] will always return default system font. You can just make use of the same function that you call in setFont which is [UIFont fontWithName:size:] .
To give a dynamic height to an UIlabel in swift we can use the frame property of UILabel. We can create a frame using the CGRect which allows us to give different variables like x position, y position, width, and height.
You should declare your label as class property, so it can be accessed from other methods
To change the font size use
[theLabel11 setFont: [UIFont fontWithName:@"Arial" size:13.0f]];
To change the frame size of the label us
theLabel11.frame = CGRectMake(x, y, width, height);
A common idiom for adjusting the spatial information on a UIView is as below
label.frame = CGRectMake(
x,
y,
width,
height
);
You can get the old position and height via
label.frame.origin.x
label.frame.origin.y
label.frame.size.width
label.frame.size.height
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