目錄:[Swift]Xcode實際操做html
本文將演示給圖片添加顏色相框ide
1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from a nib. 8 //UIImage是一個用來加載和繪製圖像的類 9 let image = UIImage(named: "picture") 10 //在將圖片從資源文件夾中加載以後, 11 //將圖片賦給圖像視圖。 12 //你能夠將圖像視圖看做是圖像的容器 13 let imageView = UIImageView(image: image) 14 15 //初始化一個原點在(24,80),尺寸爲(272,410)的矩形常量,做爲圖像視圖的顯示區域 16 imageView.frame = CGRect(x: 24, y: 80, width: 272, height: 410) 17 //設置圖像視圖的突出邊框的寬度爲10, 18 //視圖真正的繪圖部分,是由一個圖層類的對象來管理的 19 imageView.layer.borderWidth = 10 20 //視圖自己,更像是一個突出的管理器, 21 //訪問它的跟繪圖和座標有關的屬性, 22 //其實是在訪問它所包含的圖層的相關屬性 23 imageView.layer.borderColor = UIColor.lightGray.cgColor 24 25 //將圖片視圖添加到當前視圖控制器的根視圖 26 self.view.addSubview(imageView) 27 } 28 }