Search
Duplicate

UILabel의 원하는 부분만 border 넣기!

생성일
2023/07/31 11:55
태그
Swift
먼저
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를 넣어주었다.