下面通过实例代码给大家详细介绍了iOS UIView常见属性方法,具体代码如下所示:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
UIView : UIResponder
/**
通过一个frame来初始化一个UI控件
*/
- (id)initWithFrame:(CGRect)frame;
// YES:能够跟用户进行交互
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default is YES
// 控件的一个标记(父控件可以通过tag找到对应的子控件)
@property(nonatomic) NSInteger tag; // default is 0
// 图层(可以用来设置圆角效果\\阴影效果)
@property(nonatomic,readonly,retain) CALayer *layer;
@interface UIView(UIViewGeometry)
// 位置和尺寸(以父控件的左上角为坐标原点(0, 0))
@property(nonatomic) CGRect frame;
// 位置和尺寸(以自己的左上角为坐标原点(0, 0))
@property(nonatomic) CGRect bounds;
// 中点(以父控件的左上角为坐标原点(0, 0))
@property(nonatomic) CGPoint center;
// 形变属性(平移\\缩放\\旋转)
@property(nonatomic) CGAffineTransform transform; // default is CGAffineTransformIdentity
// YES:支持多点触摸
@property(nonatomic,getter=isMultipleTouchEnabled) BOOL multipleTouchEnabled; // default is NO
@end
@interface UIView(UIViewHierarchy)
// 父控件
@property(nonatomic,readonly) UIView *superview;
// 子控件(新添加的控件默认都在subviews数组的后面, 新添加的控件默认都显示在最上面\\最顶部)
@property(nonatomic,readonly,copy) NSArray *subviews;
// 获得当前控件所在的window
@property(nonatomic,readonly) UIWindow *window;
// 从父控件中移除一个控件
- (void)removeFromSuperview;
// 添加一个子控件(可以将子控件插入到subviews数组中index这个位置)
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index;
// 交换subviews数组中所存放子控件的位置
- (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
// 添加一个子控件(新添加的控件默认都在subviews数组的后面, 新添加的控件默认都显示在最上面\\最顶部)
- (void)addSubview:(UIView *)view;
// 添加一个子控件view(被挡在siblingSubview的下面)
- (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview;
// 添加一个子控件view(盖在siblingSubview的上面)
- (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview;
// 将某个子控件拉到最上面(最顶部)来显示
- (void)bringSubviewToFront:(UIView *)view;
// 将某个子控件拉到最下面(最底部)来显示
- (void)sendSubviewToBack:(UIView *)view;
/**系统自动调用(留给子类去实现)**/
- (void)didAddSubview:(UIView *)subview;
- (void)willRemoveSubview:(UIView *)subview;
- (void)willMoveToSuperview:(UIView *)newSuperview;
- (void)didMoveToSuperview;
- (void)willMoveToWindow:(UIWindow *)newWindow;
- (void)didMoveToWindow;
/**系统自动调用**/
// 是不是view的子控件或者子控件的子控件(是否为view的后代)
- (BOOL)isDescendantOfView:(UIView *)view; // returns YES for self.
// 通过tag获得对应的子控件(也可以或者子控件的子控件)
- (UIView *)viewWithTag:(NSInteger)tag; // recursive search. includes self
/**系统自动调用(留给子类去实现)**/
// 控件的frame发生改变的时候就会调用,一般在这里重写布局子控件的位置和尺寸
// 重写了这个写方法后,一定调用[super layoutSubviews];
- (void)layoutSubviews;
@end
@interface UIView(UIViewRendering)
// YES : 超出控件边框范围的内容都剪掉
@property(nonatomic) BOOL clipsToBounds;
// 背景色
@property(nonatomic,copy) UIColor *backgroundColor; // default is nil
// 透明度(0.0~1.0)
@property(nonatomic) CGFloat alpha; // default is 1.0
// YES:不透明 NO:透明
@property(nonatomic,getter=isOpaque) BOOL opaque; // default is YES
// YES : 隐藏 NO : 显示
@property(nonatomic,getter=isHidden) BOOL hidden;
// 内容模式
@property(nonatomic) UIViewContentMode contentMode; // default is UIViewContentModeScaleToFill
@end
//动画
@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;
@end
|
相关文章
猜你喜欢
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 35
-
2025-05-25 22
-
2025-05-29 93
-
Win10ctrl键失灵怎么办?Win10ctrl键失灵的解决方法
2025-05-27 64 -
2025-05-29 100
热门评论

