먼저
extension UILabel {
func addBottomBorder(with color: UIColor?, andWidth borderWidth: CGFloat) {
let border = UIView()
border.backgroundColor = color
border.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
border.frame = CGRect(x: 0, y: self.frame.height - borderWidth, width: self.frame.width, height: borderWidth)
self.addSubview(border)
}
}
Swift
복사
extension을 넣어주고
firstLabel.addBottomBorder(with: UIColor.lightGray, andWidth: CGFloat(1.0))
secondLabel.addBottomBorder(with: UIColor.lightGray, andWidth: CGFloat(1.0))
thirdLabel.addBottomBorder(with: UIColor.lightGray, andWidth: CGFloat(1.0))
Swift
복사
원하는 label에 넣어준다.
•
아래쪽 면에만 border를 넣어주었다.