UIButton未出现在iOS 9的视图中 [英] UIButton is not appear on view in iOS 9

查看:55
本文介绍了UIButton未出现在iOS 9的视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在iOS 8中创建了我的项目,它可以正常工作,现在我试图在iOS9中运行.UIButton没有出现.我已经以编程方式创建了一个按钮,但它不仅出现在iOS9中.它可以在iOS7和iOS8中正常工作.请参见下面的代码.

I have created my project in iOS 8 it works fine and now i am trying to run in iOS9.UIButton is not appearing. I have created a button programmatically, but it is not appearing only in iOS9. It works fine in iOS7 and iOS8. Please see the below code.

    UIButton *NewOrderButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [NewOrderButton addTarget:self action:@selector(ButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [NewOrderButton setTitle:@"Create" forState:UIControlStateNormal];
    NewOrderButton.frame = CGRectMake((self.view.frame.size.width-200)/2,(self.view.frame.size.height+80)/2, 200, 40.0);
    [NewOrderButton.layer setBorderWidth:1];
    [NewOrderButton.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    NewOrderButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.view addSubview:NewOrderButton];

如果我调试此代码,则该按钮将出现.

If i debug this code, then the button is appearing.

推荐答案

Elavarasan我在viedDidLoad和viewDidLayoutSubviews中应用了您的编码,效果很好.还请设置按钮的背景色.下面是代码.再次应用此代码肯定会得到解决方案的.

Elavarasan I applied your coding in viedDidLoad and viewDidLayoutSubviews,it works fine.Also please set the background color for the button.Below is the code.Again apply this code in your class.Definitely you will get solution.

UIButton *NewOrderButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[NewOrderButton addTarget:self action:@selector(ButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[NewOrderButton setTitle:@"Create" forState:UIControlStateNormal];
NewOrderButton.backgroundColor = [UIColor blueColor];
NewOrderButton.frame = CGRectMake((self.view.frame.size.width/250)/2,(self.view.frame.size.height+80)/2, 200, 40.0);
[NewOrderButton.layer setBorderWidth:1];
[NewOrderButton.layer setBorderColor:[[UIColor greenColor] CGColor]];
NewOrderButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[self.view addSubview:NewOrderButton];

这篇关于UIButton未出现在iOS 9的视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆