gpt4 book ai didi

IOS 调整 UILabel 宽度

转载 作者:行者123 更新时间:2023-11-28 22:02:51 24 4
gpt4 key购买 nike

如何调整IOS中UIlabel的宽度?我有定义

    @property (strong, nonatomic) IBOutlet UILabel *label;

在 viewcontroller.h 中。

下面是view controller.m中的代码

    - (IBAction)btn_click:(id)sender {
self.label.text = @"TEXT";
self.label.font = [UIFont boldSystemFontOfSize:20.0];
self.label.backgroundColor = [UIColor clearColor];
self.label.frame = CGRectMake(50,50,300,25);
[self.label sizeToFit];

[self.view addSubview:self.label];
}

除 UILabel 宽度外,一切正常。如何调整 UIlabel 的宽度?

谢谢

最佳答案

如果你想要一个漂亮的动画,你可以将它添加到 UIView 动画 block 中,就像这样:

- (IBAction)btn_click:(id)sender  
{
self.label.text = @"TEXT";
self.label.font = [UIFont boldSystemFontOfSize:20.0];
self.label.backgroundColor = [UIColor clearColor];
[UIView animateWithDuration:0.33f animations:^{
self.label.frame = CGRectMake(50, 50, 300, 25);

}];
}

关于IOS 调整 UILabel 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24692881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com