【问题标题】:Button behaving differently in 6.1 vs. 7.0按钮在 6.1 和 7.0 中的行为不同
【发布时间】:2013-10-18 13:38:28
【问题描述】:

我有以下代码来显示一个简单的按钮:

button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
button.center = CGPointZero
button.frame = [[container.width/2-button.frame.size.width/2,150], [280,50]]
button.setTitle("Categorize New Project", forState: UIControlStateNormal)
button.addTarget(self, 
                 action: "moveToChildView:",
                 forControlEvents: UIControlEventTouchUpInside)

当我在 6.1 的模拟器 iPhone 视网膜(3.5 英寸)中运行这个应用程序时,它看起来像这样:

但是,当我在模拟器 iPhone 视网膜 7.0 中运行它时,它看起来像这样:

是否需要更改此代码才能在 7.0 中正常工作?

【问题讨论】:

    标签: iphone ios ios7 rubymotion ios6.1


    【解决方案1】:

    从 iOS 7 开始,默认的圆角矩形按钮如下所示。请参阅UI transition guide。我建议使用自定义按钮来防止版本之间出现这种差异。

    【讨论】:

    • 最好的做法是 UIButtonTypeCustom,正如 Alexander 建议的那样
    • 如果我在 Rakefile 中将app.deployment_target 设置为 6.1,那么在 ios7 上的用户会不会觉得该应用正常?
    • @Alexander 请你在这里提供示例代码,因为我可能在我的项目中使用了错误的代码,你的示例代码可以帮助我改进我的项目
    【解决方案2】:

    正如Alexander所说,这是iOS7的新外观,他也建议使用自定义按钮,which is good advice
    但是这里有另一种解决这个问题的方法,它会给你下面的输出

    使用此代码

    self.myButton.layer.cornerRadius = 10;
    self.myButton.backgroundColor = [UIColor whiteColor];
    self.myButton.layer.borderWidth = 1.0f;
    

    【讨论】:

    • 谢谢 如果我在 Rakefile 中将app.deployment_target 设置为 6.1,那么在 ios7 上的人看来,该应用程序是否正常?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-10
    • 2018-08-13
    • 1970-01-01
    • 1970-01-01
    • 2018-11-03
    • 1970-01-01
    相关资源
    最近更新 更多