iOS基础控件 UILabel Swift3.1

2017-06-16  本文已影响0人  zzcz_cc
//
//  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.
    }
    */

}
上一篇下一篇

猜你喜欢

热点阅读