如何在iOS中制作这样的按钮UI?

时间:2016-09-30 09:07:55

标签: ios iphone user-interface mobile uibutton

我想像这样制作这个按钮的ui,它将支持所有的iphone和ipad屏幕

enter image description here

2 个答案:

答案 0 :(得分:2)

您可以使用CAGradientLayer。虽然结果并不完全相同,但它比按钮大小更改时设置背景图像更有优势。

以下代码已准备好用于Xcode Playground:

(units * unit_price) / (enddate - startdate in days)

enter image description here

答案 1 :(得分:0)

Swift 2.3

的代码变化不大

button.backgroundColor = UIColor.darkGrayColor()

    let gradientLayer = CAGradientLayer()
    gradientLayer.frame = button.bounds
    gradientLayer.startPoint = CGPoint(x: 0, y: 0.5) //Set the start point to the left edge center
    gradientLayer.endPoint = CGPoint(x: 1, y: 0.5) //Set end point to the right edge center
    gradientLayer.colors = [UIColor.clearColor().CGColor, UIColor.redColor().colorWithAlphaComponent(0.5).CGColor, UIColor.redColor().colorWithAlphaComponent(0.5).CGColor, UIColor.clearColor().CGColor]
    gradientLayer.locations = [0, 0.2, 0.8, 1] //At the start point, the clear color is used; at 20% horizontal, red is used, etc

    button.layer.insertSublayer(gradientLayer, atIndex: 0)
相关问题