본문 바로가기
iOS/iOS

UILabel에 이미지 넣기

by 패쓰킴 2022. 4. 20.
728x90
let iconAttachment = NSTextAttachment()
iconAttachment.image = UIImage(named: 이미지명)?.withRenderingMode(.alwaysTemplate)
let iconOffsetY : CGFloat = -2.0;
iconAttachment.bounds = CGRect(x: -4, y: iconOffsetY, width: 16.0, height: 16.0)
            
let attachmentString = NSAttributedString(attachment: iconAttachment)
let labelText = NSMutableAttributedString(string: " ")
labelText.append(attachmentString)
labelText.append(NSMutableAttributedString(string: 텍스트))
            
label?.textAlignment = .center
label?.attributedText = labelText

 

728x90

'iOS > iOS' 카테고리의 다른 글

뒤로가기 스와이프 감지  (0) 2022.06.02
Local DB 결정 시 참고 사이트  (0) 2022.04.22
PDFView  (0) 2022.04.11
image scrolling(paging) & zoom  (0) 2022.04.04
Firebase DynamicLinks  (0) 2022.04.01

댓글