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. Win7 32位系统下Java开发环境的安装及配置

    目录: Java JDK安装. Java JDK系统环境的配置. 配置常见问题的解决. Java JDK的安装 Java Jdk(Java Development Kit)Java开发不可缺少的环境, ...

  2. iOS开发中遇到的一些问题及解决方案【转载】

    iOS开发中遇到的一些问题及解决方案[转载] 2015-12-29 [385][scrollView不接受点击事件,是因为事件传递失败] // //  MyScrollView.m //  Creat ...

  3. pair/sort/find/qsort

    1. pair template <class T1, class T2> struct pair { typedef T1 first_type; typedef T2 second_t ...

  4. nodejs 保存 payload 发送过来的文件

    1:接受文件 http://stackoverflow.com/questions/24610996/how-to-get-uploaded-file-in-node-js-express-app-u ...

  5. Hibernate学习笔记(一):mycelipse建立项目流程(未完成)

    1.部署数据库: 2.部署项目: 3.引入Hibernate: 4.url配置

  6. ByteArrayOutputStream的用法

    ByteArrayOutputStream类是在创建它的实例时,程序内部创建一个byte型别数组的缓冲区,然后利用ByteArrayOutputStream和ByteArrayInputStream的 ...

  7. 新浪研发中心: Berkeley DB 使用经验总结

    http://blog.sina.com.cn/s/blog_502c8cc40100yqkj.html NoSQL是现在互联网Web2.0时代备受关注的技术之一,被用来存储大量的非关系型的数据.Be ...

  8. Oracle instr用法

    1:实现indexOf功能,.从第1个字符开始,搜索第1次出现子串的位置 ,) as i from dual; select instr('oracle','or') as i from dual; ...

  9. HornetQ

    https://github.com/flsusp/http-queue https://github.com/sfr-network-service-platforms/hq-console htt ...

  10. Qt5.3企业版和开源版功能区别

    一: Charts Charts是QT提供的图表模块.他提供了非常简便的APIs来绘制令人惊叹的Line, Spline,Area,Scatter,Pie,Donut,Bar,Polar和Box-an ...