美文网首页
UIView控件

UIView控件

作者: 112233香樟树 | 来源:发表于2016-11-18 17:29 被阅读0次

 1.ViewController.swift

import UIKitclass ViewController: UIViewController {    override func viewDidLoad() {        super.viewDidLoad()       

 //获取当前控制器的view,设置背景颜色为红色     

   //self.view.backgroundColor = UIColor.red      

  //初始化方法,设置大小坐标       

 let rect = CGRect(x: 30, y: 30, width: 100, height: 200)        let subview:UIView = UIView(frame:rect)        

//把子视图加载上父视图  

      subview.backgroundColor = UIColor.red        self.view.addSubview(subview)        

//frame相对于父视图  

      let subview1 = UIView()        subview1.frame = CGRect(x: 140, y: 240, width: 100, height: 100)      subview1.backgroundColor = UIColor.yellow        self.view.addSubview(subview1)                      

  //center       

 let subview3 = UIView()        self.view.addSubview(subview3)        subview3.frame = CGRect(origin: self.view.center, size: CGSize(width: 20, height: 20))            subview3.backgroundColor = #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)         

 //透明度       

 //subview3.alpha = 0.1  会影响视图        subview3.backgroundColor = UIColor(colorLiteralRed: 0.5, green: 0.5, blue: 0.5, alpha: 0.5)        let subview4 = UIView(frame: CGRect(x: 10, y: 10, width: 40, height: 40))        subview4.backgroundColor = #colorLiteral(red: 0.5725490451, green: 0, blue: 0.2313725501, alpha: 1)        subview3.addSubview(subview4)       

 //tag值使用2000以上,100以下系统用        subview4.tag = 10001        let Tagview = subview3.viewWithTag(10001)        print("subview4 = \(subview4),Tagview = \(Tagview)")                //subview4.isHidden = true

 //隐藏        //用户交互    

    self.view.isUserInteractionEnabled = true     

     //superview是父试图      print("subview = \(subview4.superview),subview3 = \(subview3)")    for item in self.view.subviews{            

//从父试图上移除   

       // item.removeFromSuperview()            print(item)                            }            }    override func touchesBegan(_ touches: Set, with event: UIEvent?) {

print("点击了当前控制器")

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

}

}

相关文章

  • 2019-05-04ios 中在UIview中添加UIview

    ios 中在UIview中添加UIview A子控件,之后在UIview A子控件上添加一个UIbutton控件,...

  • iOS开发-UIView

    UIView 什么是UIView UIVIew就是控件/视图 用户在屏幕上看到的东西都是UIView 它是所有控件...

  • IOS UI继承

    UIresponder 所有控件都是UIview的子类 任意控件都可以add-UIview; background...

  • 第四节:UIView控件的使用和MVC模型

    1.UIView简介 2.UIView的继承关系 3.父控件 子控件 每个控件都是个容器,能容纳其他控件 内部小控...

  • UIView的基本使用

    UIView UI控件的基类,拥有尺寸、位置、背景色等基本属性。其他的控件继承自UIVIew。 UIView的常见...

  • IOS的UI继承

    图1 图2 所有控件都是UIView的子类,任意控件都可以addSubView 所有UIView控件都有的属性:b...

  • 给UIView控件换成渐变色

    需求:给UIView控件换成渐变色(UILabel、UIButton、UIView)

  • 12-22(让某视图在当前屏幕最上层显示)

    可以考虑获取当前顶层的窗口来添加UIView控件。 UIView *aView = [[UIView alloc]...

  • UI控件的继承关系

    所以类都继承NSObject 所有控件都是UIView的子类,所以都可以addSubView另个控件 UIView...

  • UI继承

    UIresponder 所有的控件都是UIView的子类 任意控件都可以add-UIView。 越晚添加视图越在最...

网友评论

      本文标题:UIView控件

      本文链接:https://www.haomeiwen.com/subject/pkerpttx.html