如果我使用此代码在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上显示
解决方法 目前还不清楚iOS 8中的标签有什么不同,但如果你在标签上调用layoutIfNeeded,则可以解决问题(需要在设置框架后),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中显示子视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)