gpt4 book ai didi

ios - UIView 无法识别 subview

转载 作者:行者123 更新时间:2023-12-01 18:20:31 25 4
gpt4 key购买 nike

我需要以编程方式创建一个带有 UILabel subview 的 UIView,因为它比 IB 动画效果更好。我无法让 UIView 识别 UILabel。这是我来自 viewDidLoad 的代码:

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(764, 94, 200, 100)];
[label setText:@"Hello"];
[label setTextColor:[UIColor redColor]];
[label setBackgroundColor:[UIColor clearColor]];

UIView *hintView = [[UIView alloc]initWithFrame:CGRectMake(764, 94, 240, 198)];
[hintView setBackgroundColor:[UIColor colorWithRed:(34/255.f) green:(59/255.f) blue:(27/255.f) alpha:(255/255.f)]];

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

NSLog(@"subview %@", hintView.subviews);

谢谢

最佳答案

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(764, 94, 200, 100)];

你正在设置宽框架试试这个
 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 100)];

关于ios - UIView 无法识别 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17691770/

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