UIButton不支持iPhone4

时间:2015-03-23 14:23:10

标签: ios objective-c iphone uibutton

我正在以编程方式创建一个UIButton,当我在iPhone 6上发短信时,它几乎可以正常工作,但在iPhone 5上它开始更加努力,而在iPhone 4/4上它根本不起作用。它的作用就像内部攻丝区域越来越小。我想提一下UI看起来一样,这是我正在使用的代码:

//add exit button
dismisSignInViewButton = [[UIButton alloc] init];
dismisSignInViewButton.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width * 0.87, [[UIScreen mainScreen] bounds].size.height * 0.07, 31, 31);
dismisSignInViewButton.backgroundColor = [UIColor redColor];
[dismisSignInViewButton addTarget:self
                           action:@selector(dismisSignInViewButtonFunction)
                 forControlEvents:UIControlEventTouchUpInside];
[dismisSignInViewButton setBackgroundImage:[UIImage imageNamed:@"exitButton.png"] forState:UIControlStateNormal];
[self.view addSubview:dismisSignInViewButton];
[dismisSignInViewButton setEnabled:YES];
[dismisSignInViewButton setHidden:NO];

我还试图看看它是否可以使用/不启用和隐藏属性,但它不起作用,任何想法可能出现错误?

答案:

错误是我在导航栏下绘制UIButton,在我的情况下是透明的,所以我修改了添加按钮的方式,而不是将它添加到self.view我将它添加到keyWindow所以它将被添加到顶部。这是最终的代码:

//add exit button
    dismisSignInViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
    dismisSignInViewButton.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width * 0.87, [[UIScreen mainScreen] bounds].size.height + [[UIScreen mainScreen] bounds].size.height * 0.07, 31, 31);
    dismisSignInViewButton.backgroundColor = [UIColor redColor];
    [dismisSignInViewButton addTarget:self
                               action:@selector(dismisSignInViewButtonFunction)
                     forControlEvents:UIControlEventTouchUpInside];
    [dismisSignInViewButton setBackgroundImage:[UIImage imageNamed:@"exitButton.png"] forState:UIControlStateNormal];
    [[UIApplication sharedApplication].keyWindow addSubview:dismisSignInViewButton];
    [dismisSignInViewButton setEnabled:YES];
    [dismisSignInViewButton setHidden:NO];

0 个答案:

没有答案