[英]Why is my button not being rounded in RubyMotion?
我在RubyMotion应用中有一个按钮,该应用是在视图控制器类的viewDidLoad
方法中创建的。 看起来像这样:
def viewDidLoad
@button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
@button.setTitle("Tap!", forState: UIControlStateNormal)
@button.frame = [ [85, 250], [150, 50] ]
@button.backgroundColor = UIColor.darkGrayColor
@button.addTarget(self, action: :actionForTheButton, forControlEvents: UIControlEventTouchUpInside)
self.view.addSubview(@button)
end
但是,我的按钮如下所示:
我无法理解为什么按钮会发生这种情况,因为我认为包含UIButtonTypeRoundedRect
参数的buttonWithType
方法使一个带有圆角的矩形按钮成为可能。 任何人都可以澄清这里的问题吗?
最好不要使用UIButtonTypeRoundedRect
。 源: https : //developer.apple.com/library/ios/documentation/uikit/reference/UIButton_Class/UIButton/UIButton.html
您可以通过在图层上设置cornerRadius来舍入任何UIView。
我建议像这样四舍五入您的UIView层:
def viewDidLoad
@button = UIButton.buttonWithType(UIButtonTypeSystem)
@button.setTitle("Tap!", forState: UIControlStateNormal)
@button.frame = [ [85, 250], [150, 50] ]
@button.layer.cornerRadius = 10 # SET THE ROUNDING RADIUS HERE
@button.backgroundColor = UIColor.darkGrayColor
@button.addTarget(self, action: :actionForTheButton, forControlEvents: UIControlEventTouchUpInside)
self.view.addSubview(@button)
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.