TIL
[TIL] 2022 / 07 / 30
희철
2022. 7. 30. 19:52
DataDetector
텍스트뷰에는 dataDetector라는 것이 있음.
텍스트뷰에 입력된 텍스트를 감지해서 다양한 기능을 만들어줌.
하지만 이 기능을 이용하려면 isEditing이 false로 되어있어야함!!
-> 즉, 내가 텍스트뷰에 입력하는 것이 아닌 미리 코드로 작성해야함.
Detector이기때문에 타입을 link로 해놓고 url이 입력되어있다면 인식하지 못함.
1. link
userInputTextView.dataDetectorTypes = .link
userInputTextView.text = "www.naver.com"
userInputTextView.isEditable = false
2. PhoneNumber
userInputTextView.dataDetectorTypes = .phoneNumber
userInputTextView.text = "01000000000"
userInputTextView.isEditable = false
3. address
userInputTextView.dataDetectorTypes = .address
userInputTextView.text = "1600 Pennsylvania Ave NW, Washington, DC 20500"
userInputTextView.isEditable = false
"서울시 송파구"로 입력했을땐 인식하지 못했음.
-> 백악관 주소를 입력하니 지도 앱으로 넘어가서 보여줌.
-> 아마 주소를 정확하게 입력해야 넘어가는듯함.
4. calendarEvent
온갖 포맷으로 다해봐도 인식을 못했음.
이 외에도 flightNumber, lookUpSuggestion 등이 있는데 잘 인식이 안됐음.
NSTextAttachment
TextAttachment를 이용해서 이미지를 텍스트에 넣어봄.
let attributedString = NSMutableAttributedString(string: "안녕")
let attachment = NSTextAttachment(image: UIImage(named: "겨울왕국2")!)
attachment.bounds = CGRect(x: 0, y: 0, width: 20, height: 20)
attributedString.append(NSAttributedString(attachment: attachment))
userInputTextView.attributedText = attributedString
______________________________________________________________________________________________________
다마고치 코드 수정
-> 따로