gpt4 book ai didi

ios - UILabel 在 iOS8 中不显示 subview

转载 作者:可可西里 更新时间:2023-11-01 03:43:20 24 4
gpt4 key购买 nike

目前我为背景制作了一个背面标签,并在 UILabel 上添加了 UIButton。它在 iOS 7 中显示,但在 iOS 8 中未显示。如果我用 UIView 替换 UILabel 那么它工作正常。

如果我在 iOS 8 中使用 UILabel 使用此代码显示 UILabel 和 subview UIButton

 UILabel *downLabel = [[UILabel alloc]init];
downLabel.frame = CGRectMake(0, SCREEN_HEIGHT*0.92, SCREEN_WIDTH,SCREEN_HEIGHT*0.08 );
[downLabel setBackgroundColor:[UIColor colorWithRed:(66/255.f) green:(67/255.f) blue:(63/255.f) alpha:1]];
downLabel.userInteractionEnabled = YES;
[self.view addSubview:downLabel];

UIButton *downbtnobj = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*0.68,downLabel.frame.size.height/10,SCREEN_WIDTH*0.30,downLabel.frame.size.height/1.25)];

UIImage *btndownImage = [UIImage imageNamed:@"img 3.png"];
[downbtnobj setImage:btndownImage forState:UIControlStateNormal];
[downbtnobj addTarget:self action:@selector(bulletInButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[downLabel addSubview:downbtnobj];

enter image description here

现在您可以看到只有 UILabel 正在显示,但 UILabel 上没有显示按钮。

另一个这个如果我用 UIView 替换 UILabel 那么它显示完美。

    UIView *downLabel = [[UIView alloc]init];
downLabel.frame = CGRectMake(0, SCREEN_HEIGHT*0.92, SCREEN_WIDTH,SCREEN_HEIGHT*0.08 );
[downLabel setBackgroundColor:[UIColor colorWithRed:(66/255.f) green:(67/255.f) blue:(63/255.f) alpha:1]];
downLabel.userInteractionEnabled = YES;
[self.view addSubview:downLabel];

UIButton *downbtnobj = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*0.68,downLabel.frame.size.height/10,SCREEN_WIDTH*0.30,downLabel.frame.size.height/1.25)];
UIImage *btndownImage = [UIImage imageNamed:@"img 3.png"];
[downbtnobj setImage:btndownImage forState:UIControlStateNormal];
[downbtnobj addTarget:self action:@selector(bulletInButtonClicked) forControlEvents:UIControlEventTouchUpInside];
[downLabel addSubview:downbtnobj];

在这段代码中,您可以看到我只用 UIView 替换了 UILabel。现在显示按钮。 enter image description here

可以帮忙解释为什么 iOS8 中的 UILabel 上没有显示 subview 吗

最佳答案

目前尚不清楚 iOS 8 中的标签有何不同,但如果您在标签上调用 layoutIfNeeded,就可以解决问题(需要在设置框架之后),

UILabel *downLabel = [[UILabel alloc]init];
downLabel.frame = CGRectMake(0, SCREEN_HEIGHT*0.92, SCREEN_WIDTH,SCREEN_HEIGHT*0.08 );
[downLabel layoutIfNeeded];
[downLabel setBackgroundColor:[UIColor colorWithRed:(66/255.f) green:(67/255.f) blue:(63/255.f) alpha:1]];
downLabel.userInteractionEnabled = YES;
[self.view addSubview:downLabel];

编辑后:

我还发现,如果您设置文本(在创建标签后的任何时间),则会出现该按钮。

关于ios - UILabel 在 iOS8 中不显示 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27199387/

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