Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- tableView
- ios
- Human interface guide
- collectionview
- 리펙토링
- scrollview
- 클린 코드
- UITextView
- swift documentation
- rxswift
- MVVM
- UICollectionView
- HIG
- Clean Code
- map
- RxCocoa
- Refactoring
- 리팩토링
- 애니메이션
- Xcode
- 스위프트
- uiscrollview
- Protocol
- ribs
- Observable
- SWIFT
- uitableview
- clean architecture
- combine
- swiftUI
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] String에 strikeThrough 적용 (AttributedString) 본문
iOS 실전 (swift)
[iOS - swift] String에 strikeThrough 적용 (AttributedString)
jake-kim 2020. 11. 24. 12:00AttributedString과 String의 차이
- String은 단순히 text만 존재
- AttributedString은 text에 attribute(속성 - Font, color, style등)이 추가 된 것
- 코드로 String의 attribute를 지정할 수 있는 장점
Label에 strike속성을 코드로 넣기

- String의 extension으로 넣어서 사용
func strikeThrough() -> NSAttributedString {
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: self)
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0, attributeString.length))
return attributeString
}
- 사용
class ViewController: UIViewController {
@IBOutlet weak var lbl: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
lbl.attributedText = lbl.text?.strikeThrough()
}
}
'iOS 실전 (swift)' 카테고리의 다른 글
Comments