1_UILabel

时间:2024-01-09 16:40:38
//
// ViewController.swift
// 1_UILabel
//
// Created by Larry on 2016/12/7.
// Copyright © 2016年 nfIOS. All rights reserved. import UIKit class ViewController: UIViewController { override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let label = UILabel(frame: CGRect(x: , y: , width: , height: ))
//设置字体内容
label.text = "larry111111111111"
//设置字体颜色
label.textColor = UIColor.orange
//设置字体大小
label.font = UIFont.boldSystemFont(ofSize: )
//设置背景颜色
label.backgroundColor = UIColor.blue
//设置对齐方式
label.textAlignment = .center
//设置高亮模式(默认为false)
label.isHighlighted = true
//设置高亮模式下的字体颜色
label.highlightedTextColor = UIColor.brown
//超出label边界文字的截取方式
label.lineBreakMode = .byClipping
//是否能与用户交互(默认为false)
label.isUserInteractionEnabled = true
//设置文本文字自适应大小
label.adjustsFontSizeToFitWidth = true
//设置自动换行
label.numberOfLines =
//设置是否可改
label.isEnabled = false
//文本阴影颜色
label.shadowColor = UIColor.darkGray
//阴影大小
label.shadowOffset = CGSize(width: , height: )
//baselineAdjustment这个值控制文本的基线位置,只有文本行数为1是有效
/*
UIBaselineAdjustmentAlignBaselines = 0,默认,文本最上端与中线对齐。
UIBaselineAdjustmentAlignCenters, 文本中线与label中线对齐。
UIBaselineAdjustmentNone, 文本最低端与label中线对齐。
*/
label.baselineAdjustment = .alignBaselines
//minimumScaleFactor控制字体大小自适应(默认为0.0)
//设置最小收缩比例,如果Label宽度小于文字长度时,文字进行收缩,收缩超过比例后,停止收缩。
label.minimumScaleFactor = 0.5
label.adjustsFontForContentSizeCategory = true
label.allowsDefaultTighteningForTruncation = true self.view.addSubview(label)
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
} }

相关文章