일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 페이스북
- node
- NeXT
- hybrid
- node.js
- angular4
- react
- 안드로이드
- 웹뷰
- beanstalk
- 네이티브
- TypeScript
- nextjs
- 카카오톡
- swift
- S3
- AWS
- php
- 감사일기
- fanzeel
- https
- angular
- Route53
- 알려줌
- 도메인
- Elastic Beanstalk
- cors
- JavaScript
- ios
- Android
- Today
- Total
쪼렙 as! 풀스택
Swift - UILabel 에 부분적으로 Bold 처리한 텍스트 입력하기. 17.11.21. 본문
UILabel 에 부분적으로 Bold 처리하고 싶을 때가 많이 있다.
AttributedString 을 쓰면 되는데,
이게 매번 쓰기가 참 귀찮다.
그래서,편하게 "Bold" 스타일과, "Normal" 스타일을 번갈아가면서, 마음대로 Attributed String 을 만드는 Extension 을 만들어서 간단히 해결.
extension NSMutableAttributedString {
func bold(_ text: String, fontSize: CGFloat) -> NSMutableAttributedString {
let attrs: [NSAttributedStringKey: Any] = [.font: UIFont.boldSystemFont(ofSize: fontSize)]
self.append(NSMutableAttributedString(string: text, attributes: attrs))
return self
}
func normal(_ text: String, fontSize: CGFloat) -> NSMutableAttributedString {
let attrs: [NSAttributedStringKey: Any] = [.font: UIFont.systemFont(ofSize: fontSize)]
self.append(NSMutableAttributedString(string: text, attributes: attrs))
return self
}
}
사용하기.
let attributedString = NSMutableAttributedString()
.bold("두꺼운 문자열", fontSize: 15)
.normal("보통 문자열", fontSize: 15)
uiLabel.attributedText = attrString;
'개발 일지 > iOS & Android' 카테고리의 다른 글
구글플레이 Signing 키로, 페이스북 용 Key Hash 만들기. (0) | 2018.02.12 |
---|---|
17.11.26. 페이스북 Swift SDK 사용. LoginManager 로 로그인, GraphAPI 사용하기. (0) | 2017.11.27 |
17. 10. 12. Swift4 마이그레이션. APNS 인증서 갱신하기. (0) | 2017.10.12 |
Android - HTML 형식의 TextView 에서 <img> 태그 이용하여 이미지 불러오기. (0) | 2017.06.15 |
Android - Module 이용하여 비슷한 앱 여러개 찍어내기 (1) | 2017.06.08 |