gpt4 book ai didi

ios - sizeToFit 和约束

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:48:36 25 4
gpt4 key购买 nike

我有一个观点:

my view

label1 和label2 之间存在布局约束。按下按钮将 TextView 中的文本添加到 label1。在调整标签 1 的大小以适合文本后(调用 sizeToFit)。调整大小后,约束似乎不起作用:

constraint

有人知道如何使约束起作用吗?

我的代码:

@interface ViewController ()
{
CGFloat _width;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
}

- (void) viewDidAppear:(BOOL)animated
{

_width = self.l1.frame.size.width;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)addText:(id)sender {
self.l1.text = [NSString stringWithFormat:@"%@ %@", self.l1.text, self.text.text];
self.l1.frame = CGRectMake(self.l1.frame.origin.x, self.l1.frame.origin.y, _width, 0);
[self.l1 sizeToFit];
}
@end

最佳答案

我找到了原因:高度约束等于标签 1 的 40。当我将其更改为 greater 或 equal 时,所有其他约束都可以正常工作。

关于ios - sizeToFit 和约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12973689/

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