1

I want to make a button with top left and botton left corner radius = 15 so i make this class to achive it

    class pathBUtton:UIBUtton{
       override func layoutSubviews() {
          super.layoutSubviews()
          let shapeLayer = CAShapeLayer()
          let path = UIBezierPath.init(roundedRect: self.bounds, byRoundingCorners: [.topLeft,.bottomLeft], cornerRadii: CGSize.init(width: 15.0, height: 0.0))
          shapeLayer.lineWidth = 5.0
          shapeLayer.fillColor = UIColor.blue.cgColor
          shapeLayer.path = path.cgPath
          shapeLayer.strokeColor = UIColor.clear.cgColor
          self.backgroundColor = UIColor.clear
          self.layer.addSublayer(shapeLayer)
    }

after setting button class in IB to pathButton, the button text is not shown see image and also the cashapelayer is not fitting the button frame, the white seen behinde the blue. the blue part is the button, the white is the view containig the button an a label an other button. in the view controller i have set the views cornerradius to 15 as this

valoraView.layer.cornerRadius = 15

but there is a diference between the radius of the view and the radius of the shapelayer in the path. so any help would be apreciated

Yoel Jimenez del valle
  • 1,270
  • 1
  • 9
  • 20
  • Why don't you just set the corner radius of those two corners? There's no need for the shape layer, and in any case the shape layer doesn't actually do any rounding (it's not masking the button). – matt Apr 18 '18 at 00:55

1 Answers1

2

I want to make a button with top left and botton left corner radius = 15

self.button.layer.cornerRadius = 15
self.button.layer.borderWidth = 2
self.button.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMinXMinYCorner]

enter image description here

matt
  • 515,959
  • 87
  • 875
  • 1,141