-4

I want the result to be exact as the given image.

How can I create a slant button like the image given below?

image

I don't want to use image as backgroud.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Jaseel.Dev
  • 730
  • 1
  • 7
  • 19
  • Take a look here https://stackoverflow.com/questions/36877085/how-to-make-the-frame-of-a-button-custom-shape-in-swift-2 There is also an answer for Swift 3/4 – wades Apr 16 '19 at 07:03
  • it didn't helped me ..as i only want top make one side of a botton to be slant and change angle degree – Jaseel.Dev Apr 16 '19 at 08:50

1 Answers1

1

I've just made this:

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

wades
  • 250
  • 2
  • 10