UIView常见属性

今天把UI view的一些常用的属性做了一个总结,也是之前自己做的笔记。感觉对于初学者来说可能会有点用处,不说废话了,看具体内容吧!

  1 @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem>
  2
  3 /**
  4  *  通过一个frame来初始化一个UI控件
  5  */
  6 - (id)initWithFrame:(CGRect)frame;
  7
  8 // YES:能够跟用户进行交互
  9 @property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;  // default is YES
 10
 11 // 控件的一个标记(父控件可以通过tag找到对应的子控件)
 12 @property(nonatomic)                                 NSInteger tag;                // default is 0
 13
 14 // 图层(可以用来设置圆角效果\阴影效果)
 15 @property(nonatomic,readonly,retain)                 CALayer  *layer;
 16
 17 @end
 18
 19 @interface UIView(UIViewGeometry)
 20 // 位置和尺寸(以父控件的左上角为坐标原点(0, 0))
 21 @property(nonatomic) CGRect            frame;
 22
 23 // 位置和尺寸(以自己的左上角为坐标原点(0, 0))
 24 @property(nonatomic) CGRect            bounds;
 25
 26 // 中点(以父控件的左上角为坐标原点(0, 0))
 27 @property(nonatomic) CGPoint           center;
 28
 29 // 形变属性(平移\缩放\旋转)
 30 @property(nonatomic) CGAffineTransform transform;   // default is CGAffineTransformIdentity
 31
 32 // YES:支持多点触摸
 33 @property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled;   // default is NO
 34 @end
 35
 36 @interface UIView(UIViewHierarchy)
 37 // 父控件
 38 @property(nonatomic,readonly) UIView       *superview;
 39
 40 // 子控件(新添加的控件默认都在subviews数组的后面, 新添加的控件默认都显示在最上面\最顶部)
 41 @property(nonatomic,readonly,copy) NSArray *subviews;
 42
 43 // 获得当前控件所在的window
 44 @property(nonatomic,readonly) UIWindow     *window;
 45
 46 // 从父控件中移除一个控件
 47 - (void)removeFromSuperview;
 48
 49 // 添加一个子控件(可以将子控件插入到subviews数组中index这个位置)
 50 - (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
 51
 52 // 交换subviews数组中所存放子控件的位置
 53 - (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
 54
 55 // 添加一个子控件(新添加的控件默认都在subviews数组的后面, 新添加的控件默认都显示在最上面\最顶部)
 56 - (void)addSubview:(UIView *)view;
 57
 58 // 添加一个子控件view(被挡在siblingSubview的下面)
 59 - (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
 60
 61 // 添加一个子控件view(盖在siblingSubview的上面)
 62 - (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
 63
 64 // 将某个子控件拉到最上面(最顶部)来显示
 65 - (void)bringSubviewToFront:(UIView *)view;
 66
 67 // 将某个子控件拉到最下面(最底部)来显示
 68 - (void)sendSubviewToBack:(UIView *)view;
 69
 70 /**系统自动调用(留给子类去实现)**/
 71 - (void)didAddSubview:(UIView *)subview;
 72 - (void)willRemoveSubview:(UIView *)subview;
 73
 74 - (void)willMoveToSuperview:(UIView *)newSuperview;
 75 - (void)didMoveToSuperview;
 76 - (void)willMoveToWindow:(UIWindow *)newWindow;
 77 - (void)didMoveToWindow;
 78 /**系统自动调用**/
 79
 80 // 是不是view的子控件或者子控件的子控件(是否为view的后代)
 81 - (BOOL)isDescendantOfView:(UIView *)view;  // returns YES for self.
 82
 83 // 通过tag获得对应的子控件(也可以或者子控件的子控件)
 84 - (UIView *)viewWithTag:(NSInteger)tag;     // recursive search. includes self
 85
 86 /**系统自动调用(留给子类去实现)**/
 87 // 控件的frame发生改变的时候就会调用,一般在这里重写布局子控件的位置和尺寸
 88 // 重写了这个写方法后,一定调用[super layoutSubviews];
 89 - (void)layoutSubviews;
 90
 91 @end
 92
 93 @interface UIView(UIViewRendering)
 94 // YES : 超出控件边框范围的内容都剪掉
 95 @property(nonatomic)                 BOOL              clipsToBounds;
 96
 97 // 背景色
 98 @property(nonatomic,copy)            UIColor          *backgroundColor; // default is nil
 99
100 // 透明度(0.0~1.0)
101 @property(nonatomic)                 CGFloat           alpha;                      // default is 1.0
102
103 // YES:不透明  NO:透明
104 @property(nonatomic,getter=isOpaque) BOOL              opaque;                     // default is YES
105
106 // YES : 隐藏  NO : 显示
107 @property(nonatomic,getter=isHidden) BOOL              hidden;
108
109 // 内容模式
110 @property(nonatomic)                 UIViewContentMode contentMode;                // default is UIViewContentModeScaleToFill
111 @end
112 //属性改变时添加动画
113 @interface UIView(UIViewAnimationWithBlocks)
114 + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
115 + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
116
117 + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;
118 + (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;
119 @end
时间: 2024-08-29 10:33:11

UIView常见属性的相关文章

UIView 常见属性

UIView 常见属性 UIView 常见属性 NSArray *subviews 获取所有的子控件(前提必须是加载在该视图上) 数组的顺序决定着子控件的显示层级顺序(下标越大的,越显示在上面) UIView的常见方法 addSubview 添加一个子控件 使用这个方法添加的子控件会被塞到subViews数组的最后面 可以使用下面的方法调整子控件在subViews数组中的顺序 //将子控件view插入到subviews数组的index位置 -(void)insertSubview:(UIView

UIView常见属性总结

一 UIVIew 常见属性 1.frame 位置和尺寸(以父控件的左上角为原点(0,0)) 2.center 中点 (以父控件的左上角为原点(0,0)) 3.bounds 位置和尺寸(以自己的左上角为原点 (0,0)) 4.transform 形变属性(缩放,旋转) 5.backgroundColor 背景颜色 6.tag 标识(父控件可以根据这个标识找到对应的子控件,同一个父控件中的子控件不要一样) 7. hidden 设置是否要隐藏 8.alpha 透明度(0~1); 9.opaque 不透

UIView常见属性与方法

常见属性: @property(nonatomic,readonly) UIView    *superview; 获得自己的父控件对象 @property(nonatomic,readonly,copy) NSArray   *subviews; 获得自己的所有子控件对象 @property(nonatomic) NSInteger   tag; 控件的ID(标识),父控件可以通过tag来找到对应的子控件 @property(nonatomic) CGAffineTransform   tra

UIView常见属性详解

转载学习自http://www.cnblogs.com/hukezhu/p/4499994.html 上篇大体介绍了一些空间的常见属性,本篇主要介绍一下UIVIew的常见属性. 首先引入上一篇介绍的UIView的常见属性: //控件所在矩形框在父控件中的位置和尺寸(以父控件的左上角为坐标原点) @property(nonatomic) CGRect frame; //控件所在矩形框的位置和尺寸(以自己左上角为坐标原点,所以bounds的x\y一般为0) @property(nonatomic)

UI基础UIView常见属性及方法

1.NSBundle 1> 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2> 利用mainBundle就可以访问软件资源包中的任何资源 3> 模拟器应用程序的安装路径 /Users/aplle/资源库/Application Support/iPhone Simulator/7.1/Applications 2.UIImageView和UIButton 1> 使用场合 * UIImageView: 如果仅仅是显示图片,不需要监听图片的点击 * UIB

UIView常见属性方法

UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem>/** *  通过一个frame来初始化一个UI控件 */- (id)initWithFrame:(CGRect)frame; // YES:能够跟用户进行交互@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;  // d

(6)UIView常见属性二

例如创建一个view视图,view是最纯洁的控制,必须得指定它的位置,而不像其他的控件像UISwitch默认都有一个位置 在viewDidLoad方法中打印它的位置: 将控件放入一个视图中,只需移动白色的视图,里面的子控件也会跟着移动,因为里面的控件的frame是相对子父控件左上角为坐标原点 注意:bounds和frame的相同点都是能表示宽度和高度,所以获取控件的宽度和高度有两种方法一种是通过bounds另一种是通过frame 而获取位置(x\y)值只能通过self.view.frame.or

(5)UIView常见属性

此时打印的所有子控件会把使用自动布局的控件也打印出来,不准确,所以得去掉这两个选项,再进行打印 使用实例如下: viewWithTag的注意点,当有多个相同的Tag值时,它是先找到第一个Tag值,而不会继续找下去了,它是按照添加顺序来查找的 使用insertSubview: aboveSubview:方法将视图插入到在哪个视图之上 总结: 怎么验证它呢,可以通过如下来修改它的位置来观看变化,如下:

UIView常见属性设置汇总

1.圆角设置 viewT.layer.cornerRadius = 10;//设置那个圆角的有多圆 viewT.layer.borderWidth = 10;//设置边框的宽度,当然可以不要 viewT.layer.borderColor = [[UIColor redColor] CGColor];//设置边框的颜色 viewT.layer.masksToBounds = YES;//设为NO去试试 2.