I want the result to be exact as the given image.
How can I create a slant button like the image given below?
I don't want to use image as backgroud.
I want the result to be exact as the given image.
How can I create a slant button like the image given below?
I don't want to use image as backgroud.
I'll leave the colors to you but here's what I did:
@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()
}
Copy and Paste that, hook up your buttons. Let me know how you go