常见属性和方法

一 、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 不透明度(0~1);
10.userInteractionEnabled 能否跟用户进行交互(YES 能交互)
11.superView 父控件
12.subviews 子控件
13.contentMode 内容显示的模式 拉伸自适应
例如:
[view viewWithTag:10]; UIView常见方法
1.addSubview
添加子控件,被添加到最上面(subviews中的最后面) 2.removeFromSuperview
从父控件中移除 3.viewWithTag:
父控件可以根据这个tag 标识找到对应的控件(遍历所有的子控件) 4.insertSubview:atIndex:
添加子控件到指定的位置 5.利用两个类方法来执行动画的两个方法
+(void) beginAnimations:(NSString *)animationID context:(void *)context;
/**..需要执行动画的代码..**/
+(void) commitAnimations; 6.利用blok 执行动画
/*
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 能否处理
2>contentVerticalAlignment 内容在垂直方向上的排布方式
3>contentHorizontalAlignment 内容在水平方向上的排布方式
5.常用方法
1> 添加监听器
/*
target 监听器对象
action 事件触发时所调用的方法,调用target的方法
*/
-(void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents; 2> 删除监听器
//删除监听器后,事件触发时就不会再通知监听器了,也就不会再调用target的action方法了
-(void roemoveTarget:(id)target action:](SEL)action forControlEvents:](UIControlEvents) controlEvents); 3> 获得所有的监听器对象
-(NSSet *) allTargets; 三、UILabel
1.常见属性
1>text 所显示的文本内容
2>textColor 文本颜色
3> font 字体
4> shadowColor 文字的阴影颜色
5> shadowOffset 阴影的偏差距离(width水平方向的偏差距离,height垂直方向的念头距离,正数下边)
6> textAlignment 设置文字的排布方法(偏左,偏右,居中).
7>numberOfLines 允许文字最多有几行数(如果为0,自动换行).
四、UIButton
//.UISlider .UISwitch .UIDatePicker等等
1.常见属性 1>titleLabel 获取内部的UILabel 对象
2>imageView 获取内部的UIImageView对象 2.常见方法
1>设置内部UILabel 显示的文本内容
//设置按钮文本的时候不能 btn .titleLabel.text = @"4324324";
- (void)setTitle:(NSString *)title forState:(UIControlState)state; // default is nil. title is assumed to be single line 2> 设置内部UILabel的文字颜色
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default if nil. use opaque white
3>设置内部UILabel 的文字阴影颜色
- (void)setTitleShadowColor:(UIColor *)color forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil. use 50% black
4>设置内部UIImageView的图片
- (void)setImage:(UIImage *)image forState:(UIControlState)state; // default is nil. should be same size if different for different states
5>设置内部UIImageView的图片
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state UI_APPEARANCE_SELECTOR; // default is nil 6>下面两个方法需要交给子类去重写
//返回没物控部UILabel的frame (位置和尺寸)
-(CGRect)titleRectForContentRect:(CGRect)contentRect;
//返回内部UIImage的尺寸和位置
-(CGRect)imageRectForContentRect:(CGRect) contentRect; 7> 下面这些方法可以获取不同状态下的一些属性
- (NSString *)titleForState:(UIControlState)state; // these getters only take a single state value
- (UIColor *)titleColorForState:(UIControlState)state;
- (UIColor *)titleShadowColorForState:(UIControlState)state;
- (UIImage *)imageForState:(UIControlState)state;
- (UIImage *)backgroundImageForState:(UIControlState)state;
- (NSAttributedString *)attributedTitleForState:(UIControlState)state NS_AVAILABLE_IOS(6_0);

iOS:UIView、UIControl、UIButton、UILabel简单的属性和方法常识的更多相关文章

  1. ios基础篇(四)——UILabel的常用属性及方法

    UILabel的常用属性及方法:1.text //设置和读取文本内容,默认为nil label.text = @”文本信息”; //设置内容 NSLog(@”%@”, label.text); //读 ...

  2. UIButton 头文件常见属性和方法

    UIButton头文件常见属性 1.属性 contentEdgeInsets: default is UIEdgeInsetsZero.设置内容四边距,默认边距为0 @property(nonatom ...

  3. IOS UIView(UIButton)通过显示动画移动的时候 响应点击的解决方案

    今天在做一个UIButton显示动画的时候,遇到一个问题,就是在移动的时候 ,需要相应它的点击时间(click) 通过CAKeyframeAnimation 来移动UIButton的layer ,效果 ...

  4. UILabel的各种属性和方法

    转自:http://liulu200888an.blog.163.com/blog/static/3498972320121214208542/ UILabel  *label1 = [[UILabe ...

  5. UILabel的各种属性与方法的使用

    //设置字体:粗体,正常的是 SystemFontOfSize label1.font = [UIFont boldSystemFontOfSize:20]; //设置文字颜色 label1.text ...

  6. 关于ios的autoLayout的一些简单介绍以及使用方法

    一.autoLayout的用途: 主要用于屏幕适配,尤其是出现了iphone6,plus之后. 二.怎么简单的用autoLayout呢? 点击左一,可以看到: 点击左二: 基本上要想autolayou ...

  7. iOS UIView控件的常用属性和方法的总结

    一 UIVIew 常见属性1.frame 位置和尺寸(以父控件的左上角为原点(0,0))2.center 中点 (以父控件的左上角为原点(0,0))3.bounds 位置和尺寸(以自己的左上角为原点 ...

  8. iOS学习21之UILabel, UITextField, UIButton, UIImageView

    1.UILabel 1> 概述 UILabel (标签): 是显示文本的控件.在App中 UILabel 是出现频率最高的控件 UILabel 是 UIView 子类,作为子类一般是为了扩充父类 ...

  9. [转]IOS UIView 之属性篇

    [转载自:IOS UIView 之属性篇 From CSDN] UIView 继承于UIResponder             所遵守的协议有 NSCoding .UIAppearance. UI ...

随机推荐

  1. 【linux】crontab定时命令

    参考来源: http://blog.csdn.net/ariessurfer/article/details/7459183 http://www.jb51.net/LINUXjishu/19905. ...

  2. ZOJ-3430

    Detect the Virus  Time Limit: 2 Seconds      Memory Limit: 65536 KB One day, Nobita found that his c ...

  3. mac下谷歌chrome浏览器的快捷键

    1. 标签页和窗口快捷键 ⌘-N 打开新窗口. ⌘-T 打开新标签页. ⌘-Shift-N 在隐身模式下打开新窗口. 按 ⌘-O,然后选择文件. 在 Chrome 浏览器中打开计算机中的文件. 按住  ...

  4. python 字典value排序

    #!/usr/bin/env python#coding:utf-8s = {“a”:1,”b”:3,”c”:2} print sorted(s.iteritems(),key=lambda t:t[ ...

  5. poj 3404&&poj1700(贪心)

    Bridge over a rough river Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4143   Accept ...

  6. hdu 2818(并查集,带权更新)

    Building Block Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. CentOS7.5更改grub2菜单背景&开机动态画面

    Grub2菜单背景 红帽企业版 Linux 7 的引导装载程序是“GRUB 2”.您可以更改“GRUB 2”外观的几个部分.以下几小节将向您展示如何改变 Linux 发行版名称.菜单颜色,和背景图片. ...

  8. CF 某套题 O :Grid (简单BFS)

    题意: 从左上角跳到右下角最少需要多少步,跳的规则为:可以向四个方向的任意一个方向跳当前格子中的步数,若跳不到右下角输出IMPOSSIBLE. 题解: BFS搜索,注意判断边界,标记. 代码: #in ...

  9. mysql查看表结构,字段等命令

    mysql查看表结构命令,如下: desc 表名; show columns from 表名; describe 表名; show create table 表名;

  10. 洛谷P3197 HNOI2008 越狱

    题目传送门 实际上昨天大鸡哥已经讲过这题了,结果没记住,今天一道相似的题就挂了......吃一堑长一智啊. 思路大致是这样:如果直接算发生越狱的情况会比较复杂,所以可以用间接法,用安排的总方案-不会发 ...