How to change an UILabel/UIFont's letter spacing?

后端 未结 5 1381
小蘑菇
小蘑菇 2020-12-02 12:32

I\'ve searched loads already and couldn\'t find an answer.

I have a normal UILabel, defined this way:

    UILabel *totalColors = [[[UILabel alloc] in         


        
5条回答
  •  旧巷少年郎
    2020-12-02 12:54

    In Swift:

    let myTitle = "my title"
    let titleLabel = UILabel()
    let attributes: NSDictionary = [
        NSFontAttributeName:UIFont(name: "HelveticaNeue-Light", size: 20),
        NSForegroundColorAttributeName:UIColor.whiteColor(),
        NSKernAttributeName:CGFloat(2.0)
    ]
    let attributedTitle = NSAttributedString(string: myTitle, attributes: attributes as? [String : AnyObject])
    
    titleLabel.attributedText = attributedTitle
    titleLabel.sizeToFit()
    

提交回复
热议问题