如何改变UILabel的大小

Ara*_*han 13 iphone objective-c

我有一个以编程方式编码的UILabel.我想按下按钮时更改标签的大小.如何更改该标签的大小?这是我的代码

 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];    
Run Code Online (Sandbox Code Playgroud)

sid*_*log 17

您应该将标签声明为类属性,因此可以从其他方法访问它

要改变字体大小,请使用

[theLabel11 setFont: [UIFont fontWithName:@"Arial" size:13.0f]];
Run Code Online (Sandbox Code Playgroud)

要更改标签的框架大小我们

theLabel11.frame = CGRectMake(x, y, width, height);
Run Code Online (Sandbox Code Playgroud)


fie*_*sor 11

用于调整UIView上的空间信息的常用习语如下

label.frame = CGRectMake(
    x,
    y,
    width,
    height
);
Run Code Online (Sandbox Code Playgroud)

您可以通过以获得旧位置和高度

label.frame.origin.x
label.frame.origin.y
label.frame.size.width
label.frame.size.height
Run Code Online (Sandbox Code Playgroud)