Add Border to the Label

Puneet Maratha
1 min readJul 17, 2018

--

Right/ Left/ Top / Bottom : — — — Borders

Just Copy and Paste Below Code At the end of your class.
1. Creating Extension.
2. How To Use.

extension CALayer {func addWaghaBorder(edge: UIRectEdge, color: UIColor, thickness: CGFloat) {let border = CALayer()switch edge {case UIRectEdge.top:border.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: 1)breakcase UIRectEdge.bottom:border.frame = CGRect(x: 0, y: self.frame.height - 1, width: self.frame.width, height: 1)breakcase UIRectEdge.left:border.frame = CGRect(x: 0, y: 0, width: 1, height: self.frame.height)breakcase UIRectEdge.right:border.frame = CGRect(x: self.frame.width - 1, y: 0, width: 1, height: self.frame.height)breakdefault:break}border.backgroundColor = color.cgColor;self.addSublayer(border)}}

How To Use:- — — — — — — -

'TOP BORDER'

lbl_YourLabelName.layer.addWaghaBorder(edge: .top, color: UIColor.white, thickness: 1)

_BOTTOM BORDER_

lbl_YourLabelName.layer.addWaghaBorder(edge: .top, color: UIColor.white, thickness: 1)

RIGHT BORDER"

lbl_YourLabelName.layer.addWaghaBorder(edge: .top, color: UIColor.white, thickness: 1)

"LEFT BORDER

lbl_YourLabelName.layer.addWaghaBorder(edge: .top, color: UIColor.white, thickness: 1)

:) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :) :)

You May Like:- Trending iOS Interview Questions For Beginners.

--

--