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.改变某一行的行 ...
随机推荐
- 由MyEclipse内存不足谈谈JVM内存设置
转自:http://www.javatang.com/archives/2007/12/03/1653250.html 如果没有进行设置的话,在使用MyEclipse的经常出现如下图所示内存不足的提示 ...
- OC基础 可变数组与不可变数组的使用
OC基础 可变数组与不可变数组的使用 1.不可变数组 1.1不可变数组的创建 //实例方法 NSArray *array = [[NSArray alloc] initWithObjects:&quo ...
- C/C++中的成员函数指针声明及使用
代码: #include <iostream> using namespace std; class Test{ public: void func(){ cout<<&quo ...
- nodejs 保存 payload 发送过来的文件
1:接受文件 http://stackoverflow.com/questions/24610996/how-to-get-uploaded-file-in-node-js-express-app-u ...
- 在windows下获取硬盘序列号(win7 32位,Windows Server 64位测试,希望在其他平台测试,遇到问题的网友留言分享)
#include <Windows.h> #include <stdio.h> // IOCTL控制码 // #define DFP_SEND_DRIVE_COMMAND CT ...
- HoG feature for human detection(HoG 行人识别)
本文大部分内容总结于其他文章 1.介绍 HOG(Histogram of Oriented Gradient)是2005年CVPR会议上,法国国家计算机科学及自动控制研究所的Dalal等人提出的一种解 ...
- java设计模式--结构型模式--适配器模式
适配器模式 概述 将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 适用性 1.你想使用一个已经存在的类,而它的接口不符合你的需 ...
- mysql 的 decimal类型
最近做项目时将decimal定义成了decimal(5,2),然后等到最大的结果都是999.99,找了很多地方找不出bug在哪里插入很更新的数据都是正确的而结果却都是999.99,最后才知道decim ...
- wikioi1191 数轴染色
题目描述 Description 在一条数轴上有N个点,分别是1-N.一开始所有的点都被染成黑色.接着 我们进行M次操作,第i次操作将[Li,Ri]这些点染成白色.请输出每个操作执行后 剩余黑色点的个 ...
- Spiral Matrix 解答
Question Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ...