UIView的一些常用属性和方法 

1. UIView的属性

  UIView继承自UIResponder,拥有touches方法。

  • - (instancetype)initWithFrame:(CGRect)frame; 通过Frame来初始化一个UIView控件
  • @property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; 默认为YES 能够跟用户进行交互

  • @property(nonatomic)NSInteger tag;   控件的一个标记(父控件可以通过tag找到对应的子控件)  默认为 0

  • @property(nonatomic,readonly,strong) CALayer  *layer;   图层(可以用来设置圆角效果\阴影效果)

  @interface UIView(UIViewGeometry)

  • @property(nonatomic) CGRect   frame;   位置和尺寸(以父控件的左上角为坐标原点(0, 0))
  • @property(nonatomic) CGRect   bounds; 位置和尺寸(以自己的左上角为坐标原点(0, 0)
  • @property(nonatomic) CGPoint   center; 中点(以父控件的左上角为坐标原点(0, 0))
  • @property(nonatomic) CGAffineTransform transform;   default is CGAffineTransformIdentity   形变属性(平移\缩放\旋转)
  • @property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled;   // default is NO // YES:支持多点触摸

  @interface UIView(UIViewHierarchy)

  • @property(nonatomic,readonly) UIView       *superview;     // 父控件
  • @property(nonatomic,readonly,copy) NSArray *subviews;  // 子控件(新添加的控件默认都在subviews数组的后面, 新添加的控件默认都显示在最上面\最顶部)
  • @property(nonatomic,readonly) UIWindow     *window;     // 获得当前控件所在的window
  • - (void)removeFromSuperview;                                       // 从父控件中移除一个控件
  • - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index; // 添加一个子控件(可以将子控件插入到subviews数组中index这个位置)
  • - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2; // 交换subviews数组中所存放子控件的位置
  • - (void)addSubview:(UIView *)view;                             // 添加一个子控件(新添加的控件默认都在subviews数组的后面, 新添加的控件默认都显示在最上面\最顶部)
  • - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;                   // 添加一个子控件view(被挡在siblingSubview的下面)
  • - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview ;                 // 添加一个子控件view(盖在siblingSubview的上面)
  • - (void)bringSubviewToFront:(UIView *)view;                                                                  // 将某个子控件拉到最上面(最顶部)来显示
  • - (void)sendSubviewToBack:(UIView *)view;                                                                   // 将某个子控件拉到最下面(最底部)来显示
  • - (BOOL)isDescendantOfView:(UIView *)view;             // returns YES for self. // 是不是view的子控件或者子控件的子控件(是否为view的后代)
  • - (UIView *)viewWithTag:(NSInteger)tag;                  // recursive search. includes self // 通过tag获得对应的子控件(也可以或者子控件的子控件)
  • /**系统自动调用(留给子类去实现)**/
    - (void)didAddSubview:(UIView *)subview;
    - (void)willRemoveSubview:(UIView *)subview;

    - (void)willMoveToSuperview:(UIView *)newSuperview;
    - (void)didMoveToSuperview;
    - (void)willMoveToWindow:(UIWindow *)newWindow;
    - (void)didMoveToWindow;
    /**系统自动调用**/

  • /**系统自动调用(留给子类去实现)**/
    // 控件的frame发生改变的时候就会调用,一般在这里重写布局子控件的位置和尺寸
    // 重写了这个写方法后,一定调用[super layoutSubviews];
    - (void)layoutSubviews;

@interface UIView(UIViewRendering)

  • @property(nonatomic)                 BOOL              clipsToBounds;             // YES : 超出控件边框范围的内容都剪掉
  • @property(nonatomic,copy)            UIColor          *backgroundColor;      // default is nil     // 背景色
  • @property(nonatomic)                 CGFloat           alpha;                         // default is 1.0  // 透明度(0.0~1.0)
  • @property(nonatomic,getter=isOpaque) BOOL              opaque;             // default is YES // YES:不透明  NO:透明
  • @property(nonatomic,getter=isHidden) BOOL              hidden;               // YES : 隐藏  NO : 显示
  • @property(nonatomic)                 UIViewContentMode contentMode;       // default is UIViewContentModeScaleToFill   // 内容模式
  • 设置属性改变时的动画

@interface UIView(UIViewAnimationWithBlocks)
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;

UIView的一些常用属性和方法的更多相关文章

  1. UIView常用属性与方法/UIKit继承结构

    UIView常用属性与方法 @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDy ...

  2. UITableView常用属性和方法 - 永不退缩的小白菜

    UITableView常用属性和方法 - 永不退缩的小白菜 时间 2014-05-27 01:21:00  博客园精华区原文  http://www.cnblogs.com/zhaofucheng11 ...

  3. Node.js process 模块常用属性和方法

    Node.js是常用的Javascript运行环境,本文和大家发分享的主要是Node.js中process 模块的常用属性和方法,希望通过本文的分享,对大家学习Node.js http://www.m ...

  4. ios基础篇(四)——UILabel的常用属性及方法

    UILabel的常用属性及方法:1.text //设置和读取文本内容,默认为nil label.text = @”文本信息”; //设置内容 NSLog(@”%@”, label.text); //读 ...

  5. SVG DOM常用属性和方法介绍(1)

    12.2  SVG DOM常用属性和方法介绍 将以Adobe SVG Viewer提供的属性和方法为准,因为不同解析器对JavaScript以及相关的属性和方法支持的程度不同,有些方法和属性是某个解析 ...

  6. 第190天:js---String常用属性和方法(最全)

    String常用属性和方法 一.string对象构造函数 /*string对象构造函数*/ console.log('字符串即对象');//字符串即对象 //传统方式 - 背后会自动将其转换成对象 / ...

  7. JavaScript中Number常用属性和方法

    title: JavaScript中Number常用属性和方法 toc: false date: 2018-10-13 12:31:42 Number.MAX_VALUE--1.79769313486 ...

  8. iOS UIView控件的常用属性和方法的总结

    一 UIVIew 常见属性1.frame 位置和尺寸(以父控件的左上角为原点(0,0))2.center 中点 (以父控件的左上角为原点(0,0))3.bounds 位置和尺寸(以自己的左上角为原点 ...

  9. 12-27 UITableView常用属性及方法

    UITableView也有自己的代理协议,它本身继承自UIScrollView 一:代理要遵守代理协议<UITableViewDelegate>,代理协议中的代理方法: 1.改变某一行的行 ...

随机推荐

  1. SVN的初步使用方法

    1.需要公司提供SVN账号密码 2.cd 输入本地存储路径 3.输入服务器地址 --uesr= (账号名) --password=(账号密码) 4.本地路径会自动创建文件 5.经理会初始化项目 5.1 ...

  2. cocoa pods 安装 转载

    1.打开终端 终端输入  $ruby -v  查看ruby的版本 打印代码: ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64- ...

  3. AngularJS的$http服务的应用

    $http有很多参数和调用方法,本文只记录比较常用的应用及参数. $http 服务:只是简单封装了浏览器原生的XMLHttpRequest对象,接收一个参数,这个参数是一个对象,包含了用来生成HTTP ...

  4. JAVA采用JDBC连接操作数据库详解

    JDBC连接数据库概述 一.JDBC基础知识 JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供 ...

  5. Combination Sum,Combination Sum II,Combination Sum III

    39. Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique co ...

  6. jvm的client和server

    最近研究c++代码调用java的jar,发现64位的下的jvm在server路径,而32位的jvm则存在client路径下面,于是十分好奇,查了下,这里做个记录 JVM Server模式与client ...

  7. php,apache伪静态(1转)

    1.检测Apache是否支持mod_rewrite通过php提供的phpinfo()函数查看环境配置,通过Ctrl+F查找到“Loaded Modules”,其中列出了所有apache2handler ...

  8. pubwin 客户端会员无法自助结账的排查方法

    客户端会员无法自助结账按以下方法排查:1,看客户端能不能打开web https 后台,打不开的话,在服务端打上2048证书补丁(按下面帖子操作)http://bbs.pubwin.com.cn/for ...

  9. 当list中有中文,打印的时候显示为字符编码的问题

    当list中有中文时,print list显示的会是字符编码,比如: 用str()当然也不行: 在不安装其他包的情况下,目前我知道的解决办法是使用decode('string_escape'),如下:

  10. hadoop集群之HDFS和YARN启动和停止命令

    假如我们只有3台linux虚拟机,主机名分别为hadoop01.hadoop02和hadoop03,在这3台机器上,hadoop集群的部署情况如下: hadoop01:1个namenode,1个dat ...