Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the size of UILabel

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];    
like image 787
Aravindhan Avatar asked May 21 '11 08:05

Aravindhan


People also ask

How do you change the font size in UILabel?

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.

How do I change the label size in Xcode?

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.

How do I increase font size in Objective C?

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:] .

How do I change label height in Swift?

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.


2 Answers

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);
like image 62
sidslog Avatar answered Sep 27 '22 23:09

sidslog


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
like image 28
fieldtensor Avatar answered Sep 27 '22 23:09

fieldtensor