我希望结果精确到给定的图像。
如何创建一个倾斜按钮,如下图所示?
我不想使用图片作为背景。
答案 0 :(得分:1)
我会把颜色留给你,但这是我所做的:
@IBOutlet var callButton: UIButton!
@IBOutlet var bookButton: UIButton!
func createSlantOnButton() {
let buttonSlant = 10 as CGFloat //Change this to change the slant angle
let buttonHeight = bookButton.bounds.height
let buttonWidth = bookButton.bounds.width
let customButton = bookbutton
customButton!.backgroundColor = UIColor.green
callButton.backgroundColor = UIColor.green
let drawView = UIBezierPath()
drawView.move(to: CGPoint(x: 100.0, y: 0.0))
drawView.addLine(to: CGPoint(x: buttonWidth, y: 0.00))
drawView.addLine(to: CGPoint(x: buttonWidth, y: buttonHeight))
drawView.addLine(to: CGPoint(x: 00.0, y: buttonHeight))
drawView.addLine(to: CGPoint(x: buttonSlant, y: 00.0))
drawView.close()
let layer = CAShapeLayer()
layer.fillColor = UIColor.blue.cgColor
layer.strokeColor = UIColor.blue.cgColor
layer.path = drawView.cgPath
customButton!.layer.addSublayer(layer)
self.view.addSubview(customButton!)
}
override func viewDidLoad() {
super.viewDidLoad()
createSlantOnButton()
}
复制并粘贴,然后单击按钮。让我知道你走了