UIView的一些常用属性和方法
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的一些常用属性和方法的更多相关文章
- UIView常用属性与方法/UIKit继承结构
UIView常用属性与方法 @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDy ...
- UITableView常用属性和方法 - 永不退缩的小白菜
UITableView常用属性和方法 - 永不退缩的小白菜 时间 2014-05-27 01:21:00 博客园精华区原文 http://www.cnblogs.com/zhaofucheng11 ...
- Node.js process 模块常用属性和方法
Node.js是常用的Javascript运行环境,本文和大家发分享的主要是Node.js中process 模块的常用属性和方法,希望通过本文的分享,对大家学习Node.js http://www.m ...
- ios基础篇(四)——UILabel的常用属性及方法
UILabel的常用属性及方法:1.text //设置和读取文本内容,默认为nil label.text = @”文本信息”; //设置内容 NSLog(@”%@”, label.text); //读 ...
- SVG DOM常用属性和方法介绍(1)
12.2 SVG DOM常用属性和方法介绍 将以Adobe SVG Viewer提供的属性和方法为准,因为不同解析器对JavaScript以及相关的属性和方法支持的程度不同,有些方法和属性是某个解析 ...
- 第190天:js---String常用属性和方法(最全)
String常用属性和方法 一.string对象构造函数 /*string对象构造函数*/ console.log('字符串即对象');//字符串即对象 //传统方式 - 背后会自动将其转换成对象 / ...
- JavaScript中Number常用属性和方法
title: JavaScript中Number常用属性和方法 toc: false date: 2018-10-13 12:31:42 Number.MAX_VALUE--1.79769313486 ...
- iOS UIView控件的常用属性和方法的总结
一 UIVIew 常见属性1.frame 位置和尺寸(以父控件的左上角为原点(0,0))2.center 中点 (以父控件的左上角为原点(0,0))3.bounds 位置和尺寸(以自己的左上角为原点 ...
- 12-27 UITableView常用属性及方法
UITableView也有自己的代理协议,它本身继承自UIScrollView 一:代理要遵守代理协议<UITableViewDelegate>,代理协议中的代理方法: 1.改变某一行的行 ...
随机推荐
- python 杂记
class TestA(object): def __init__(self): print("A is initing"); def foo(self): print(" ...
- 分享到QQ空间、新浪微博、腾讯微博的代码!
给网页加上分享代码,借助网友的力量推广网站,目前已经很流行了 以下是网页代码 QQ空间分享代码如下: <a href="javascript:void(0);" onclic ...
- uva1587 Box
Ivan works at a factory that produces heavy machinery. He has a simple job -- he knocks up wooden bo ...
- CentOS终端操作mysql
1.停用mysql服务:service mysqld stop 重启mysql服务:service mysql restart 2.mysql 1045ERROR:mysqld_safe --user ...
- C语言复习--实现栈
C #include <stdio.h> #include <stdlib.h> #define STACK_SIZE 100 typedef char TYPE; typed ...
- 查看Linux系统下Raid信息
软件raid:只能通过Linux系统本身来查看 cat /proc/mdstat 可以看到raid级别,状态等信息. 硬件raid: 最佳的办法是通过已安装的raid厂商的管理工具来查看,有cmdli ...
- tyvj1297 小气的小B
描述 其实你们都不知道,小B是很小气的.一天小B带着他的弟弟小B'一起去摘果子,走着走着,他们忽然发现了一颗长满了果子的树.由于弟弟长得太矮了,弟弟只有让哥哥小B帮他摘一些果子下来.哥哥小B说:&qu ...
- SharePoint excel service web part 连接到 filter web part
本文讲述SharePoint excel service web part 连接到 filter web part的一个简单应用场景. SharePoint excel service web par ...
- php用apc实现的临界区 解决并发,资源互斥同步访问
在面对线程或进程的互斥同步的控制问题时,常用的解决办法是:临界区,互斥锁,信号量 临界区保证在某一时刻只有一个线程能够访问到所需资源的方法. 任何时候,只能至多有一个线程处于临界区中.如果多个线程要求 ...
- Linux如何生成列表
如何生成列表: 方法一:{1..100} 方法二:`seq [起始数 [步进长度]] 结束数` 1,...,100 declare -i SUM=0 integer -x