一、UIView常见属性

1.frame  位置和尺寸(以父控件的左上角为原点(0,0))

2.center 中点(以父控件的左上角为原点(0,0))

3.bounds  位置和尺寸(以自己的左上角为原点(0,0))

4.transform  形变属性(缩放、旋转)

5.backgroundColor 背景颜色

6.tag  标识(父控件可以根据这个标识找到对应的子控件,同一个父控件中的子控件tag不要一样)

7.hidden 设置是否要隐藏

8.alpha  透明度(0~1)

9.opaque 不透明度(0~1)

10.userInteractionEnabled  能否跟用户进行交互(YES能交互)

11.superview 父控件

12.subviews 子控件

13.contentMode 内容显示的模式

二、UIView常见方法

1.addSubview:

添加子控件,被添加到最上面(subviews中的最后面)

2.removeFromSuperview

从父控件中移除

3.viewWithTag:

父控件可以根据这个tag标识找到对应的子控件(遍历所有的子控件)

4.insertSubview:atIndex:

添加子控件到指定的位置

5.利用两个类方法执行动画

+ (void)beginAnimations:(NSString *)animationID context:(void *)context;

/* ...需要执行动画的代码..*/

+ (void)commitAnimations;

6.利用block执行动画

/*

duration 动画持续时间

animations 存放需要执行动画的代码

completion  存放动画完毕后需要执行的操作代码

*/

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

三、UIControl

1.只要继承了UIControl,就能简单处理一些事件(点击事件、值改变事件)

2.继承了UIControl的子类:

UIButton、UISlider、UISwitch、UIDatePicker等等

3.当需要监听一个子控件事件的时候,解决步骤:

1> 先看它是否继承自UIControl

2> 再看它内部是否有delegate属性

4.常用属性

1> enabled 能否处理事件,跟UIView的userInteractionEnabled属性类似

2> contentVerticalAlignment 内容在垂直方向上的排布方式

3> contentHorizontalAlignment 内容在水平方向上的排布方式

5.常用方法

1> 添加监听器

/*

target 监听器对象

action  事件触发时所调用的方法,调用target的方法

controlEvents 事件类型

*/

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

2> 删除监听器

// 删除监听器后,事件触发时就不会再通知监听器了,也就不会再调用target的action方法了

- (void)removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;

3> 获得所有的监听器对象

- (NSSet *)allTargets;

四、UILabel的常见属性

1.text 所显示的文本内容

2.textColor  文本颜色

3.font  字体

4.shadowColor 文字的阴影颜色

5.shadowOffset 阴影的偏差距离(width水平方向的偏差距离,正数右边、height垂直方向的偏差距离,正数下边)

6.textAlignment  设置文字的排布方式(偏左、偏右、居中)

7.numberOfLines 允许文字最多有几行(默认是1,如果为0,自动换行)

五、UIButton

1.常见属性

1> titleLabel 获取内部的UILabel对象

2> imageView 获取内部的UIImageView对象

2.常见方法

1> 设置内部UILabel显示的文本内容

// 设置按钮文本的时候不能  btn.titleLabel.text = @"4324324";

- (void)setTitle:(NSString *)title forState:(UIControlState)state;

2> 设置内部UILabel的文字颜色

- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;

3> 设置内部UILabel的文字阴影颜色

- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state;

4> 设置内部UIImageView的图片

// 设置内部UIImageView的图片不能:btn.imageView.image = [UIImage imagedName:@"0.png"];

- (void)setImage:(UIImage *)image forState:(UIControlState)state;

5> 设置背景图片

- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;

6> 下面两个方法需要交给子类去重写,然后用于重新布局button。

// 返回内部UILabel的frame(位置和尺寸)

- (CGRect)titleRectForContentRect:(CGRect)contentRect;

// 返回内部UIImageView的frame(位置和尺寸)

- (CGRect)imageRectForContentRect:(CGRect)contentRect;

7> 下面这些方法可以获取不同状态下的一些属性值

- (NSString *)titleForState:(UIControlState)state;

- (UIColor *)titleColorForState:(UIControlState)state;

- (UIColor *)titleShadowColorForState:(UIControlState)state;

- (UIImage *)imageForState:(UIControlState)state;

- (UIImage *)backgroundImageForState:(UIControlState)state;

最新文章

  1. Java发送Http请求并获取状态码
  2. Node.js的特点
  3. Nginx的nginx.conf配置文件中文注释说明
  4. Python处理JSON
  5. CoreBluetooth——IOS蓝牙4.0使用心得
  6. oracle-day1
  7. Java Thread.join()方法
  8. HTML5 文件异步上传 — h5uploader.js
  9. 实时通讯库 libre/librem/restund/baresip
  10. Esper系列(二)时间窗口、长度窗口、cast、注解、自定义函数、静态方法
  11. 动态改变EasyUI grid 列宽和隐藏列
  12. UVa1586 Molar mass
  13. MKNetWorkKit打印URL
  14. selenium 多线程
  15. 给uniGUI的表格控件uniDBGrid加上记录序号的列
  16. Environment error: “CodeBloks can't find compiler executable in your configured search path's for GNU GCC compiler”
  17. 【转】mysql给root开启远程访问权限,修改root密码
  18. List,Set的区别
  19. UVA1252 【Twenty Questions】
  20. underscore.js源码解析(四)

热门文章

  1. 我原来忽略的web开发点
  2. 自动装配Bean
  3. Java设计模式系列2--工厂方法模式(Factory Method)
  4. Android - 广播接收者 - BroadcastReceiver
  5. 黑马程序员——OC语言 核心语法(1)
  6. (C语言)结构体成员的引用->(箭头)和 .(点)
  7. oracle 拼接一张表所有字段
  8. adobe form
  9. html、css、js注释
  10. ARM compiler No such file or directory