검색결과 리스트
자동 URL 유형 처리에 해당되는 글 1건
- 2020.08.02 [iOS] - UITextView
글
[iOS] - UITextView
iOS
2020. 8. 2. 13:14
- UITextView 내용 정리
- Snapkit으로 ui-component들을 배치합니다.
- SnapKit의 기본 지식은 2020/08/01 - [iOS] - iOS - SnapKit : Layout 정리를 참고.
import Foundation
import SnapKit
class TestUITextViewVC: UIViewController {
lazy var noB_TextView : UITextView = {
let value : UITextView = UITextView()
value.backgroundColor = UIColor.cyan
value.text = "안녕하세요 No.B.Rain 입니다.
지금 여기는
https://no-b-rain.tistory.com/ 입니다."
value.textColor = UIColor.red
// 그림자를 넣고 싶다면 아래와 같이 농도를 설정
value.layer.shadowOpacity = 0.5
// Text 정렬 (왼쪽)
value.textAlignment = NSTextAlignment.left
value.font = UIFont.systemFont(ofSize: CGFloat(20))
//UIFont.systemFont(ofSize: UIFont.buttonFontSize)
//UIFont.systemFont(ofSize: UIFont.systemFontSize)
//UIFont.boldSystemFont(ofSize: UIFont.systemFontSize)
//UIFont.italicSystemFont(ofSize: UIFont.systemFontSize)
value.layer.masksToBounds = true
//value.layer.cornerRadius = "높이" * 0.05
//(둥근 모서리는 생성될 때 높이 값을 주입해서 설정)
// 테두리 설정
value.layer.borderWidth = 1
value.layer.borderColor = UIColor.black.cgColor
// 자동 URL 유형 처리
value.dataDetectorTypes = UIDataDetectorTypes.all
//UIDataDetectorTypes.address
//UIDataDetectorTypes.calendarEvent
//UIDataDetectorTypes.phoneNumber
//UIDataDetectorTypes.link
//UIDataDetectorTypes.flightNumber
// 편집 모드에서는 위의 "자동 URL 유형 처리" 기능이 동작하지 않음.
value.isEditable = false
return value
}()
lazy var noB_Label : UILabel = {
// Label 생성 => 가로 300 , 세로 300
let value : UILabel = UILabel (frame : CGRect (x: 0 , y: 0 , width: 300 , height: 100 ))
value.backgroundColor = UIColor.black
value.text = "No.B.Rain 노비의 문서"
value.textColor = UIColor.yellow
// Text 정렬 (중앙)
value.textAlignment = NSTextAlignment.center
// 둥근 모서리 => 둥근 모서리는 컨탠츠 높이의 5%가 가장 적당하고 이쁨(개인적으로..)
value.layer.masksToBounds = true
value.layer.cornerRadius = 150 * 0.05
// 그림자
value.shadowColor = UIColor.black
return value
}()
override func viewDidLoad() {
super.viewDidLoad()
//UILabel를 view에 추가
self.view.addSubview(noB_Label)
//UITextView를 view에 추가
self.view.addSubview(noB_TextView)
//화면 중앙 배치
noB_Label.snp.makeConstraints { (constraint) in
constraint.center.equalTo(self.view)
}
let nH : CGFloat = noB_Label.frame.height
noB_TextView.snp.makeConstraints { (constraint) in
//noB_TextView의 top 위치를 noB_Label의 bottom dp margine 50을 설정
constraint.top.equalTo(noB_Label.snp_bottomMargin).offset(50)
//noB_TextView의 좌/우측 기준을 noB_Label보다 +/-50으로 설정
constraint.left.equalTo(noB_Label.snp_leftMargin).offset(-50)
constraint.right.equalTo(noB_Label.snp_rightMargin).offset(50)
//noB_TextView의 넓이를 noB_Label의 넓이와 동일 하도록.
/** constraint.width.equalTo(noB_Label) **/
//noB_TextView의 높이를 100으로 설정
constraint.height.equalTo(nH)
}
//둥근 모서리
noB_TextView.layer.cornerRadius = nH * 0.05
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
}
'iOS' 카테고리의 다른 글
[iOS] - UILabel (0) | 2020.08.02 |
---|---|
[iOS] - SnapKit : Layout 정리 (0) | 2020.08.01 |
[iOS] - CocoaPods(코코아팟), Xcode의 Library 관리 (0) | 2020.08.01 |
[iOS] - Storyboard와 SwiftUI 없이 Project 만들기 (0) | 2020.07.31 |