UIButton没有按预期运行

时间:2015-08-13 16:05:19

标签: swift uibutton

我使用自动布局,无法弄清楚为什么在模拟器上按钮显示不同。 IB和模拟器的图片:

enter image description here

enter image description here

我让AutoLayout为我设置约束。按钮的固定距离设置为彼此,但在模拟器上不是这种情况。边界似乎也是关闭的。这是我用来设置按钮的代码:

class Colors {
let colorTop = UIColor(red: 192.0/255.0, green: 38.0/255.0, blue: 42.0/255.0, alpha: 0.05).CGColor
let colorBottom = UIColor(red: 35.0/255.0, green: 2.0/255.0, blue: 2.0/255.0, alpha: 0.05).CGColor

let gl: CAGradientLayer

init() {
    gl = CAGradientLayer()
    gl.colors = [ colorTop, colorBottom]
    gl.locations = [ 0.0, 1.0]
}
func niceButton(button : UIButton, sz : CGFloat)
{
    let color = Colors()

    button.setTitleColor(UIColor.blackColor(), forState: .Normal)
    button.setTitleColor(UIColor.grayColor(), forState: .Highlighted)
    button.titleLabel!.font =  UIFont(name: "Copperplate", size: sz)
    color.gl.frame = button.bounds
    color.gl.cornerRadius = 10.0
    //color.gl.borderWidth = 1.0
    button.layer.insertSublayer(color.gl, atIndex: 0)
}

} 谢谢你的帮助!

0 个答案:

没有答案