【问题标题】:How to create a slant button looks like this in Xcode?如何在 Xcode 中创建一个看起来像这样的倾斜按钮?
【发布时间】:2019-04-16 04:46:03
【问题描述】:

我希望结果与给定图像完全相同。

如何创建如下图所示的倾斜按钮?

我不想用图片作为背景。

【问题讨论】:

标签: swift xcode


【解决方案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()

}

复制并粘贴它,连接你的按钮。告诉我你的进展情况

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    相关资源
    最近更新 更多