大佬教程收集整理的这篇文章主要介绍了UILabel没有在iOS8中显示子视图,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我使用此代码在iOS 8中使用UILabel用于显示UILabel和子视图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];
现在您只能看到UILabel正在显示,但UILabel上没有显示按钮.
如果我用UIView取代UILabel那么它就显得很完美了.
UIView *downLabel = [[UIView alloc]init]; downLabel.frame = CGRectMake(0,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/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.现在按钮显示.
可以帮助为什么子视图没有在iOS8中的UILabel上显示
UILabel *downLabel = [[UILabel alloc]init]; downLabel.frame = CGRectMake(0,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];
编辑后:
以上是大佬教程为你收集整理的UILabel没有在iOS8中显示子视图全部内容,希望文章能够帮你解决UILabel没有在iOS8中显示子视图所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。