6_EZSwiftExtensions_View

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
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值