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. 未在本地计算机上注册"Microsoft.ACE.OLEDB.12.0"提供程序

    运行时出现了错误,提示未在本地计算机上注册"Microsoft.ACE.OLEDB.12.0"提供程序. 这个问题的原因是64位PC上安装了Office的32位版本,所以Micro ...

  2. Invalid content was found starting with element 'taglib'”

    今天在使用struts-menu制作菜单,在web.xml中写入 <taglib>      <taglib-uri>/WEB-INF/struts-menu.tld</ ...

  3. 《那些事之Log4j》什么是log4j?【专题一】

    Log4j 简介 在应用程序中添加日志记录总的来说基于三个目的: 监视代码中变量的变化情况,周期性的记录到文件中供其他应用进行统计分析工作: 跟踪代码运行时轨迹,作为日后审计的依据: 担当集成开发环境 ...

  4. SMA2SATA、PCIe2SATA转换模块(也有叫:Sata Test Fixtures)

    SMA2SATA.PCIe2SATA测试夹具(Sata Test Fixtures) 去年制作SMA2SATA.PCIe2SATA适配器的过程早就想写出来,但一直没有时间,今天星期六有个空儿,简单整理 ...

  5. w530 在ubuntu 12.04 _x64 背光调节方法

    So to get the screen brightness keys working with your Nvidia graphics card, create a file in the xo ...

  6. iscroll源码初涉

    最近尝试做web app时候,用上了神器iScroll,鉴于功力尚浅,并没有完全用好神器,所以今天特意来认真学习! 翻开官网,目前的版本是5,但是相关的文章并不多,具体的文件版本是: iscroll. ...

  7. setTimeout与setInterval方法的区别

    setTimeout与setInterval方法的区别 setTimeout()用于设定在指定的时间之后执行对应的函数或代码.,在全局作用域下执行 setTimeout(code,time[,args ...

  8. 字典:当索引不好用时2 - 零基础入门学习Python026

    字典:当索引不好用时2 让编程改变世界 Change the world by program 上节课我们学习到在一些情况下,比序列更实用的映射类型:字典.我们知道字典也有个关键符号就是大括号(也叫花 ...

  9. js 日常问题记录

    1.解决ie6下css背景图不缓存 try{ document.execCommand('BackgroundImageCache',false,true); }catch(e){} 2.为ajax设 ...

  10. 《Programming WPF》翻译 第7章 6.视频和3-D

    原文:<Programming WPF>翻译 第7章 6.视频和3-D 虽然详细地讨论视频和3-D超越了这本书的范围,但是获得这些特征的支持是值得的. 视频由MediaElement类型支 ...