美文网首页
iOS基础控件 UILabel Swift3.1

iOS基础控件 UILabel Swift3.1

作者: zzcz_cc | 来源:发表于2017-06-16 15:40 被阅读0次
    //
    //  UILabelViewController.swift
    //  DSwift
    //
    //  Created by 魂不在家 on 2017/6/16.
    //  Copyright © 2017年 魂不在家. All rights reserved.
    //
    
    import UIKit
    
    class UILabelViewController: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            // Do any additional setup after loading the view.
            
            let label111:UILabel = UILabel(frame:CGRect(x:10,y:100,width:200,height:100))
            label111.text = "dsadsa"
            
            //self.view.addSubview(label111)
            
            
            //Demo for uiLabel swift3.1
            let label:UILabel = UILabel(frame: CGRect(x: 10, y: 100, width: 200, height: 100) )
            //显示文字
            label.text = "Hello World"
            //设置字体大小
            label.font = UIFont.italicSystemFont(ofSize: 20)//斜体
            //label.font = UIFont.boldSystemFont(ofSize: 20)
            //设置字体颜色
            label.textColor = UIColor.red
            //设置背景颜色
            label.backgroundColor = UIColor.green
            //文字位置对齐方式3种
            //label.textAlignment = NSTextAlignment.left
            label.textAlignment = NSTextAlignment.center
            //label.textAlignment = NSTextAlignment.right
            //设置文字阴影 颜色和偏移
            label.shadowColor = UIColor.white
            label.shadowOffset = CGSize(width: 1, height: 1)
            //设置自动显示行数 0自动选择
            label.numberOfLines = 0
            
            //将label添加进当前视图
            self.view.addSubview(label)
        }
    
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
        
    
        /*
        // MARK: - Navigation
    
        // In a storyboard-based application, you will often want to do a little preparation before navigation
        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            // Get the new view controller using segue.destinationViewController.
            // Pass the selected object to the new view controller.
        }
        */
    
    }
    

    相关文章

      网友评论

          本文标题:iOS基础控件 UILabel Swift3.1

          本文链接:https://www.haomeiwen.com/subject/ctkmqxtx.html