--首先無論我們做什么都應該先設置windows窗口屬性
self.window = UIWindow(frame: UIScreen.main.bounds)
//設置窗口顏色
self.window?.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
self.window?.makeKeyAndVisible()
self.window?.rootViewController = UIViewController()
1.關于UILabel的操作
所謂的UILabel 標簽控件:主要用來展示文字
//設置UILabel的大小
let label = UILabel(frame: CGRect(x: 20, y: 50, width:(self.window?.bounds.size.width)! - 40, height: 100))
//其中 self.window?.bounds.size.width ?作用是獲取屏幕的寬
//設置的label的背景顏色
label.backgroundColor = UIColor.yellow
//設置的label的文本屬性
label.text = "Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions"
//設置的label的文字大小
label.font = UIFont.systemFont(ofSize: 17.0)
//設置的label的文字顏色
label.textColor = UIColor.red
// 設置的label的陰影顏色 ?使其可以美觀,有一些特效
?label.shadowColor = #colorLiteral(red: 0.1764705926, green: 0.01176470611, blue: 0.5607843399, alpha: 1
? ?// 陰影偏移量
//? ? ? ? label.shadowOffset = CGSize(width: 0, height: -5)
其中設置的label的陰影顏色,陰影偏移量可依只做了解
//文本對齊方式 可以有兩種方式
//第一種方式
label.textAlignment = NSTextAlignment.right
//第二種方式
label.textAlignment = .left
//文本的行數,默認是1行,0代表不限制行數
label.numberOfLines = 0
//換行模式
//根據單詞換行
label.lineBreakMode = .byWordWrapping
//Label和UIImageView默認他的交互式關閉的,如果要添加手勢,需要手動的把交互打開
label.isUserInteractionEnabled = true
self.window?.addSubview(label)