欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Xcode9学习笔记25 - 文本标签的自动换行UILabel,lineBreakMode

程序员文章站 2024-03-23 20:53:10
...

Xcode9学习笔记25 - 文本标签的自动换行UILabel,lineBreakMode

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let rect = CGRect(x: 10, y: 100, width: 300, height: 150)//创建一个显示区域
        let label = UILabel(frame: rect)//设置标签对象的显示区域
        label.text = "Start Developing iOS Apps (Swift) is the perfect starting point for learning to create apps that run on iPhone and iPad. View this set of incremental lessons as a guided introduction to building your first app—including the tools, major concepts, and best practices that will ease your path.";
        
        label.backgroundColor = UIColor.brown//设置标签背景色
        label.textColor = UIColor.purple//设置标签文字颜色
        label.textAlignment = NSTextAlignment.center//设置标签文字的对齐方式
        
        //设置标签文字对齐方式:以空格为界,并保留整个单词
        label.lineBreakMode = NSLineBreakMode.byWordWrapping
        label.numberOfLines = 0//设置标签对象不限制行数
        
        self.view.addSubview(label)//将标签对象添加到当前视图控制器的根视图
    }


Xcode9学习笔记25 - 文本标签的自动换行UILabel,lineBreakMode