본문 바로가기
iOS

[iOS] Label에 취소선 긋기

by thoonk: 2020. 12. 24.

ToDo 앱을 만들다가 Label에 취소선을 긋는 방법을 알아봤습니다. 

할 일이 완료되면 제목에 취소선을 그어서 표시할 때 사용할 수 있습니다. 

extension String {
	// 취소선 긋기
    func strikeThrough() -> NSAttributedString {
        let attributeString = NSMutableAttributedString(string: self)
        attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0,attributeString.length))
        return attributeString
    }
}

 

참조:

nsattributedstring

 

Apple Developer Documentation

 

developer.apple.com

'iOS' 카테고리의 다른 글

[iOS] Frame과 Bounds의 차이  (0) 2021.01.12
[iOS] UNUserNotificationCenter를 이용해서 로컬 푸시하기!  (1) 2021.01.05
[iOS] User Notification  (1) 2020.12.29
[iOS] JSON 파싱  (0) 2020.12.04
[iOS] Dispatch Queue  (0) 2020.11.23

댓글