如何改变UILabel的大小
我有一个以编程方式编码的 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];
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该将标签声明为类属性,以便可以从其他方法访问它
要更改字体大小,请使用
要更改标签的框架大小
You should declare your label as class property, so it can be accessed from other methods
To change the font size use
To change the frame size of the label us
调整 UIView 上的空间信息的常见习惯如下,
您可以通过以下方式获取旧位置和高度
A common idiom for adjusting the spatial information on a UIView is as below
You can get the old position and height via
如果只有一个标签添加到scroll1,则迭代滚动视图以在按钮操作中获取标签引用,如下所示
如果有许多标签,则在创建时为每个标签分配一个标签并在for循环中检查
If there is only one label added to scroll1 then, iterate the scrollview to get the label reference as follows in button action
if there are many labels assign a tag to each label while creating and check that in for loop