[IOS] UITextView 테두리칠하기(border)
2022. 12. 5. 23:21ㆍIOS
필자는 UITextView를 TextViewLabel로 받아와 borderTextViewLabel 함수를 통해 border값을 주었다. UITextView가 아닌 다른 UI도 다음과 같은 방법으로 Border값 주는 것이 가능하다.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var TextViewLabel: UITextField!
...
override func viewDidLoad() {
super.viewDidLoad()
self.borderTextViewLabel()
}
func borderTextViewLabel() {
let borderColor = UIColor(red: 220/255, green: 220/255, blue: 220/255, alpha: 1)
self.TextViewLabel.layer.borderColor = borderColor.cgColor
self.TextViewLabel.layer.borderWidth = 0.5
self.TextViewLabel.layer.cornerRadius = 5.0
}
...
}
다음과 같이 @IBInspectable를 사용하여 작성하는 방법도 존재한다. 따로 파일을 만들어 UITextVie를 상속받는 class를 만들어 원하는 UITextView의 class를 바꾸어 주면 된다.
import Foundation
import UIKit
class BorderTextView : UITextView {
@IBInspectable var isborder : Bool = false {
didSet{
if isborder {
let borderColor = UIColor(red: 220/255, green: 220/255, blue: 220/255, alpha: 1)
self.layer.borderColor = borderColor.cgColor
self.layer.borderWidth = 0.5
self.layer.cornerRadius = 5.0
}
}
}
}
만약 @IBInspectable를 잘 모른다면 해당 포스팅을 참고 바란다.
2022.12.02 - [IOS] - [IOS] IBInspectable, IBDesignable
[IOS] IBInspectable, IBDesignable
* 본 포스팅은 패스트캠퍼스의 "30개 프로젝트로 배우는 IOS 앱 개발 with Swift"를 참조하였습니다. IBInspectable IBInspectable은 커스텀 뷰 속성을 스토리뷰에서 바로 변경이 가능하게 만든다. inspectable의
hyukji.tistory.com
'IOS' 카테고리의 다른 글
[IOS] 데이터저장소 UserDefault (0) | 2022.12.07 |
---|---|
[IOS] UIDatePicker 사용하기(DateFormatter) (0) | 2022.12.06 |
[IOS] UITableView(2) (2) | 2022.12.03 |
[IOS] Alert, ActionSheet (0) | 2022.12.03 |
[IOS] UITableView(1) - UITableView의 기본 구조와 개념 (2) | 2022.12.02 |