티스토리 뷰

UILabel에서 부분적으로 글자의 크기나 폰트를 변경하고싶다면!!!

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
import UIKit
 
class ViewController: UIViewController {
 
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.setLabel()
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func setLabel(){
        let label = UILabel(frame: self.view.frame)
        label.textAlignment = NSTextAlignment.center//중간정렬
        
        let bigBoldFont = UIFont.boldSystemFont(ofSize: 28.0)
        
        let attrString = NSMutableAttributedString(string: "Dr.kim의 나를 위한 블로그")
        attrString.addAttribute(kCTFontAttributeName as String, value: bigBoldFont, range: NSMakeRange(06)) //0번째 글자부터 6글자
        
        label.attributedText = attrString
        
        self.view.addSubview(label)
    }
}
 
cs


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday