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. PHP 日期格式化 参数参考

    a - "am" 或是 "pm" A - "AM" 或是 "PM" d - 几日,二位数字,若不足二位则前面补零; 如: ...

  2. Struts2 技术全总结 (正在更新)

    背景:Struts1是一个高度成熟的框架,运行效率高,但其致命缺陷在于与JSP/Servlet的耦合非常紧密,因而导致了一些严重问题.其次,Struts1与Servlet API的严重耦合,使应用难以 ...

  3. Android App 沉浸式状态栏解决方案

    伴随着 Android 5.0 发布的 Material Design,让 Android 应用告别了以前的工程师审美,迎来了全新的界面,灵动的交互,也让越来越多的 App 开始遵从 material ...

  4. UIViewController的生命周期及iOS程序执行顺序

    UIViewController的生命周期及iOS程序执行顺序     当一个视图控制器被创建,并在屏幕上显示的时候. 代码的执行顺序1. alloc                         ...

  5. Android 之Activity切换动画效果

    在Activity中Android提供了overridePendingTransition(int enterAnim,int exitAnim)这个方法用于设置Activity之间切换的动画效果.o ...

  6. Codeforces 577B Modulo Sum

    http://codeforces.com/problemset/problem/577/B 题意:有n个数,求有无一个子序列满足和是m的倍数 思路:用模下的背包做,发现n是十的六次方级别,但是有个神 ...

  7. shell 脚本监控程序是否正在执行, 如果没有执行, 则自动启动该进程

    代码里面监控1个进程, 代码很简单, 我就不讲解了, 有不懂的, 可以在回复里面问. 我看见了会给予讲解. 当然了, 该脚本要执行,你需要开启系统的定时器进程 crond , 并且编辑配置文件. 执行 ...

  8. 在win7与XP系统下 C#缺省路径不同

    当我们加载文件时,若只输入文件名,在WIN7下默认是主程序所在文件夹路径 在XP下是上次本程序游览的有效路径 所以以后程序中尽量避免只传文件名

  9. 精确覆盖DLX算法模板

    代码 struct DLX { int n,id; int L[maxn],R[maxn],U[maxn],D[maxn]; ]; ) //传列长 { n=nn; ;i<=n;i++) U[i] ...

  10. Zoj3332-Strange Country II(有向竞赛图)

    You want to visit a strange country. There are n cities in the country. Cities are numbered from 1 t ...