iOS常用控件

iOS 主要控件有这么几个:

1.UILabel              

2.UITextField         

3.UIImageView      

4.UIControl           

5.UIButton             

6.UISlider              

7.UISegmentedControl    

8.UIActivityIndicatorView

9.UIAlertView

10.UIActionSheet

 

一、 UILabel 文本标签

常用属性

textColor    //标签文本的颜色

text           //文本值

font           //文本字体

textAlignment      // 对齐

numberOfLines    // 文本行数

 

二、UITextField文本输入框

常用属性

autocapitalizationType       // 自动大写类型,可禁止      

keyboardType                  //键盘类型

borderStyle                     //输入框显示样式

returnKeyType                //键盘上的return键的显示样式

clearButtonMode            //清除按钮模式

placeholder                   //输入框为空显示的提示文字

secureTextEntry            //是否提供文本隐藏特性(密码输入框)

textAlignment              //文本对齐方式

textColor                    //文本颜色

font                           //字体

text                           //文本

//方法

//将要开始输入的时候调用的方法

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField;

//将要输入结束时调用

-(BOOL)textFieldShouldEndEditing:(UITextField *)textField;

//清除文字按钮点击事件

-(BOOL)textFieldShouldClear:(UITextField *)textField;

// 键盘上的return按钮

-(BOOL)textFieldShouldReturn:(UITextField *)textField;

三、UIImageView图像视图

 属性

size   大小

scale     缩放倍数

images      获取图片对象数组

类方法

// 通过图片的名字创建图片对象

+(UIImage *)imageNamed:(NSString *)name;

//通过图片的路径创建图片对象

+(UIImage *)imageWithContentsOfFile:(NSString *)path;

//创建一个连续播放的图片对象

+(UIImage *)animatedImageWithImages:(NSArray *)images duration:(NSTimeInterval)duration;

//设置图片的拉伸区域

-(UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets;

//设置图片的上下和左右的拉伸线

-(UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth  topCapHeight:(NSInteger)topCapHeight;

//把图片对象转化成NSData对象

 NSData *UIImagePNGRepresentation(UIImage *image);

//把图片对象转化成NSData对象,可设置的图片的品质(0~1)

NSData *UIImageJPEGRepresentation(UIImage *image,CGFloat compressionQuality);

UIImageView的常用属性

image    // 图片对象

userInteractionEnabled        // 是否响应触摸事件,默认是no

highlightedlmage                // 高亮显示的图片

highlighted                        //是否高亮

animationlmages               //图片数组,用于动画播放

animationDuration            //播放动画图片的间隔时间

//初始化方法

UIImageView *imageView = [[UIImageView  alloc] initWithFrame:CGRectMake(0,0,100,100)];

imageView.image = [UIImage  imageNamed:@"1.png"];

imageView.userInteractionEnabled =YES;

//给图片视图添加图片默认状态下的图片,和高亮状态下的图片

-(id)initWithImage:(UIImage *)image highlightedImage:(UIImage *)highlighteImage;

//图像视图播放多张图片调用的方法

//开始播放图片动画

-(void)startAnimating;

//停止播放图片动画

-(void)stopAnimating;

//是否在动画态

-(BOOL)isAnimating;

 

UIButton的属性

buttonType                 //按钮显示样式类型

titleLabel                   //按钮标题文本Label对象

UIButton的常用方法

//设置指定状态对应的标题文本

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

//设置指定状态对应的标题颜色

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

//设置指定状态对应的显示图片

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

//设置指定状态对应的背景图片

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

//为按钮添加事件

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

 

UIButton 的状态

UIControlStateNormal                  //正常状态

UIControlStateHighlighted           //高亮状态 

UIControlStateDisabled              // 禁用状态

UIControlStateSelected             // 选中状态

UIControlStateApplication         //应用程序标志状态

UIControlStateReserved           // 系统保留状态

 

posted @ 2016-03-24 20:52  陈年瑞雪  阅读(130)  评论(0)    收藏  举报