import UIKit
class ViewController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
//basicUIViewExample()
viewFrameSize()
}
func basicUIViewExample()
{
let myView = UIView(x: 40, y: 80, w: 300, h: 300)
myView.backgroundColor = UIColor.orange
self.view.addSubview(myView)
print(myView.frame)
let myView2 = UIView(superView: myView)
myView2.backgroundColor = UIColor.purple
myView.addSubview(myView2)
print(myView2.frame)
let myView3 = UIView(superView: myView2, padding: 30) // padding:内边距;
myView3.backgroundColor = UIColor.magenta
myView2.addSubview(myView3)
print(myView3.frame)
}
///-- 快速获取View属性信息:
func viewFrameSize()
{
let view = UIView(x: 0, y: 80, w: 200, h: 200)
print("---1. 获取坐标值, view.x: \(view.x)")
print("view.y: \(view.y)")
print("view.w: \(view.w)")
print("view.h: \(view.h)")
print("---2. View上下左右四个方向到原点(左上角点)的距离, view.top: \(view.top)") //80.0
print("view.bottom: \(view.bottom)") //280.0
print("view.left: \(view.left)") //0.0
print("view.right: \(view.right)") //200.0
print("view.origin: \(view.origin)") //(0.0, 80.0)
print("view.size: \(view.size)") //(200.0, 200.0)
view.backgroundColor = UIColor.orange
self.view.addSubview(view)
///-- 设置:
view.x = 40
view.y = 80
view.w = 300
view.h = 400
}
}
6_EZSwiftExtensions_View
最新推荐文章于 2024-11-06 19:55:44 发布