黑马——IOS控件
2014-06-27 13:30
127 查看
IOS的UI控件使用
// 如果userInteractionEnabled=NO,不能跟用户交互
@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;
// 控件的标记(父控件通过标记可以找到对应的子控件)
@property(nonatomic) NSInteger tag;
// 控件的位置和尺寸(以父控件的左上角为坐标原点)
@property(nonatomic) CGRect frame;
// 控件的位置和尺寸(以控件本身的左上角为坐标原点)
@property(nonatomic) CGRect bounds;
// 控件的中点位置(以父控件的左上角为坐标原点)
@property(nonatomic) CGPoint center;
// 形变属性:旋转、缩放、平移
@property(nonatomic) CGAffineTransform transform;
// 父控件
@property(nonatomic,readonly)
UIView *superview;
// 所有的子控件
@property(nonatomic,readonly,copy)
NSArray *subviews;
// 显示的文字
@property(nonatomic,copy)
NSString *text;
// 字体
@property(nonatomic,retain)
UIFont *font;
// 文字颜色
@property(nonatomic,retain)
UIColor *textColor;
// 文字的排列方式(左对齐、居中、右对齐)
@property(nonatomic) NSTextAlignment textAlignment;
// 设置行数(行数==0代表自动换行)
@property(nonatomic) NSInteger numberOfLines;
// 显示的图片
@property(nonatomic,retain)
UIImage *image;
// 设置序列帧图片数组(按顺序播放animationImages数组中的图片)
@property(nonatomic,copy)
NSArray *animationImages;
// 序列帧动画的持续时间
@property(nonatomic) NSTimeInterval animationDuration;
// 序列帧动画的执行字数(默认是0,代表无限循环)
@property(nonatomic) NSInteger animationRepeatCount;
// 表示UIScrollView所滚动的位置
@property(nonatomic) CGPoint contentOffset;
// 表示UIScrollView的内容尺寸(能滚动的范围)
@property(nonatomic) CGSize
contentSize;
// 增加UIScrollView额外的边缘滚动区域
@property(nonatomic) UIEdgeInsets
contentInset;
// 代理
@property(nonatomic,assign) id<UIScrollViewDelegate>
delegate;
/ / 重写delegate方法:
-(NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexpath;
如果需要出现UITableView上滑动cell时出现删除按钮的话,需要进行一下操作:
首先设置你的UITableViewCell的EditingStyle是UITableViewCellEditingStyleDelete,这个时候有多种方法,
一是创建cell的时候直接设置,
二是在tableview的delegate中设置,delegate方法如下:
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath;
针对响应的indexpath返回UITableViewCellEditingStyleDelete。
三是你不要尝试自己设置cell的editingStyle属性也不要重载方法二中的方法,这样默认状态下cell的editingStyle值即为UITableViewCellEditingStyleDelete。
其次是最关键的,你一定要重载uitableview的这个delegate方法,否则是无法滑动弹出删除按钮的,
-(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath;
原因想想应该也简单,如果没有这个函数你根本就无法找到触发点击那个弹出删除按钮后的方法。
如果会对按钮的出现和消失的时刻感兴趣,那么此刻要实现代理的方法(下面的2 3):
(1)- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
(2)- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath*)indexPath
(3)- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath*)indexPath
在删除按钮显示出来之前会调用(2)方法,给我们处理问题的时间。
其实上述方法的调用顺序就是 (2)--->(1)----->(3)
而UITableView编辑时如何能移动UITableViewCell也简单,即实现UITableView的moveRow这个方法:
-(void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)indexPath toIIndexPath:(NSIndexPath*)indexPath;
这样当你设置UITableView的editing为YES的时候就会出现移动cell的那种按钮了。
// 是否可用
@property(nonatomic,getter=isEnabled) BOOL enabled;
// 自动拥有很多种状态
// 可以通过下面的方法来监听控件内部的一些事件:点击、值改变
- (void)addTarget:(id)target action:(SEL)action
forControlEvents:(UIControlEvents)controlEvents;
// 设置模式(类型)
@property(nonatomic) UIDatePickerMode datePickerMode;
// 设置区域(zh_CN代表天朝)
@property(nonatomic,retain)
NSLocale *locale;
// 设置当前时间
@property(nonatomic,retain)
NSDate *date;
// UIDatePicker内部显示的日期更改了,就会触发值改变事件
// 控制开关状态
@property(nonatomic,getter=isOn) BOOL on;
- (void)setOn:(BOOL)on animated:(BOOL)animated;
// UISwitch内部开关状态更改了,就会触发值改变事件
// 一共有多少块区域
@property(nonatomic,readonly)
NSUInteger numberOfSegments;
// 当前选中区域的位置
@property(nonatomic) NSInteger selectedSegmentIndex;
// UISegmentControl内部选中的区域更改了,就会触发值改变事件
// 设置当前的进度值
@property(nonatomic) float value;
// 设置最小的进度值
@property(nonatomic) float minimumValue;
// 设置最大的进度值
@property(nonatomic) float maximumValue;
// UISlider内部的进度值更改了,就会触发值改变事件
// 快速创建一个按钮
+ (id)buttonWithType:(UIButtonType)buttonType;
// 设置按钮的内边距
@property(nonatomic) UIEdgeInsets contentEdgeInsets;
// 按钮内部的标签控件
@property(nonatomic,readonly,retain)
UILabel *titleLabel;
// 按钮内部的图片控件
@property(nonatomic,readonly,retain)
UIImageView *imageView;
// 设置内部titleLabel显示的文字
- (void)setTitle:(NSString *)title forState:(UIControlState)state;
// 设置内部titleLabel的文字颜色
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
// 设置内部imageView显示的图片
- (void)setImage:(UIImage *)image forState:(UIControlState)state;
// 设置背景图片
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;
- (NSString *)titleForState:(UIControlState)state;
- (UIColor *)titleColorForState:(UIControlState)state;
- (UIImage *)imageForState:(UIControlState)state;
- (UIImage *)backgroundImageForState:(UIControlState)state;
// 创建一个UIAlertView对话框
/*
title : 对话框标题
message : 对话框中间显示的文字内容
cancelButtonTitle : 取消按钮的文字
otherButtonTitles : 其他按钮的文字(设置多个)
delegate : 用来监听alertView上面按钮的点击
*/
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /*<UIAlertViewDelegate>*/)delegate
cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
// 显示
- (void)show;
1.UIView
// 如果userInteractionEnabled=NO,不能跟用户交互@property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteractionEnabled;
// 控件的标记(父控件通过标记可以找到对应的子控件)
@property(nonatomic) NSInteger tag;
// 控件的位置和尺寸(以父控件的左上角为坐标原点)
@property(nonatomic) CGRect frame;
// 控件的位置和尺寸(以控件本身的左上角为坐标原点)
@property(nonatomic) CGRect bounds;
// 控件的中点位置(以父控件的左上角为坐标原点)
@property(nonatomic) CGPoint center;
// 形变属性:旋转、缩放、平移
@property(nonatomic) CGAffineTransform transform;
// 父控件
@property(nonatomic,readonly)
UIView *superview;
// 所有的子控件
@property(nonatomic,readonly,copy)
NSArray *subviews;
2.UILabel
// 显示的文字@property(nonatomic,copy)
NSString *text;
// 字体
@property(nonatomic,retain)
UIFont *font;
// 文字颜色
@property(nonatomic,retain)
UIColor *textColor;
// 文字的排列方式(左对齐、居中、右对齐)
@property(nonatomic) NSTextAlignment textAlignment;
// 设置行数(行数==0代表自动换行)
@property(nonatomic) NSInteger numberOfLines;
3.UIImageView
// 显示的图片@property(nonatomic,retain)
UIImage *image;
// 设置序列帧图片数组(按顺序播放animationImages数组中的图片)
@property(nonatomic,copy)
NSArray *animationImages;
// 序列帧动画的持续时间
@property(nonatomic) NSTimeInterval animationDuration;
// 序列帧动画的执行字数(默认是0,代表无限循环)
@property(nonatomic) NSInteger animationRepeatCount;
4.UIScrollView
// 表示UIScrollView所滚动的位置@property(nonatomic) CGPoint contentOffset;
// 表示UIScrollView的内容尺寸(能滚动的范围)
@property(nonatomic) CGSize
contentSize;
// 增加UIScrollView额外的边缘滚动区域
@property(nonatomic) UIEdgeInsets
contentInset;
// 代理
@property(nonatomic,assign) id<UIScrollViewDelegate>
delegate;
5.UITableView
/ / 重写delegate方法:
-(NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexpath;
如果需要出现UITableView上滑动cell时出现删除按钮的话,需要进行一下操作:
首先设置你的UITableViewCell的EditingStyle是UITableViewCellEditingStyleDelete,这个时候有多种方法,
一是创建cell的时候直接设置,
二是在tableview的delegate中设置,delegate方法如下:
-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath;
针对响应的indexpath返回UITableViewCellEditingStyleDelete。
三是你不要尝试自己设置cell的editingStyle属性也不要重载方法二中的方法,这样默认状态下cell的editingStyle值即为UITableViewCellEditingStyleDelete。
其次是最关键的,你一定要重载uitableview的这个delegate方法,否则是无法滑动弹出删除按钮的,
-(void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath;
原因想想应该也简单,如果没有这个函数你根本就无法找到触发点击那个弹出删除按钮后的方法。
如果会对按钮的出现和消失的时刻感兴趣,那么此刻要实现代理的方法(下面的2 3):
(1)- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
(2)- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath*)indexPath
(3)- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath*)indexPath
在删除按钮显示出来之前会调用(2)方法,给我们处理问题的时间。
其实上述方法的调用顺序就是 (2)--->(1)----->(3)
而UITableView编辑时如何能移动UITableViewCell也简单,即实现UITableView的moveRow这个方法:
-(void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)indexPath toIIndexPath:(NSIndexPath*)indexPath;
这样当你设置UITableView的editing为YES的时候就会出现移动cell的那种按钮了。
7.UIControl
@property(nonatomic,getter=isEnabled) BOOL enabled;
// 自动拥有很多种状态
// 可以通过下面的方法来监听控件内部的一些事件:点击、值改变
- (void)addTarget:(id)target action:(SEL)action
forControlEvents:(UIControlEvents)controlEvents;
1> UIDatePicker
// 设置模式(类型)@property(nonatomic) UIDatePickerMode datePickerMode;
// 设置区域(zh_CN代表天朝)
@property(nonatomic,retain)
NSLocale *locale;
// 设置当前时间
@property(nonatomic,retain)
NSDate *date;
// UIDatePicker内部显示的日期更改了,就会触发值改变事件
2> UISwitch
// 控制开关状态@property(nonatomic,getter=isOn) BOOL on;
- (void)setOn:(BOOL)on animated:(BOOL)animated;
// UISwitch内部开关状态更改了,就会触发值改变事件
3> UISegmentControl
// 一共有多少块区域@property(nonatomic,readonly)
NSUInteger numberOfSegments;
// 当前选中区域的位置
@property(nonatomic) NSInteger selectedSegmentIndex;
// UISegmentControl内部选中的区域更改了,就会触发值改变事件
4> UISlider
// 设置当前的进度值@property(nonatomic) float value;
// 设置最小的进度值
@property(nonatomic) float minimumValue;
// 设置最大的进度值
@property(nonatomic) float maximumValue;
// UISlider内部的进度值更改了,就会触发值改变事件
5> UIButton
// 快速创建一个按钮+ (id)buttonWithType:(UIButtonType)buttonType;
// 设置按钮的内边距
@property(nonatomic) UIEdgeInsets contentEdgeInsets;
// 按钮内部的标签控件
@property(nonatomic,readonly,retain)
UILabel *titleLabel;
// 按钮内部的图片控件
@property(nonatomic,readonly,retain)
UIImageView *imageView;
// 设置内部titleLabel显示的文字
- (void)setTitle:(NSString *)title forState:(UIControlState)state;
// 设置内部titleLabel的文字颜色
- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state;
// 设置内部imageView显示的图片
- (void)setImage:(UIImage *)image forState:(UIControlState)state;
// 设置背景图片
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state;
- (NSString *)titleForState:(UIControlState)state;
- (UIColor *)titleColorForState:(UIControlState)state;
- (UIImage *)imageForState:(UIControlState)state;
- (UIImage *)backgroundImageForState:(UIControlState)state;
6> UITextField(通过delegate监听内部的事件)
8.UIAlertView
// 创建一个UIAlertView对话框/*
title : 对话框标题
message : 对话框中间显示的文字内容
cancelButtonTitle : 取消按钮的文字
otherButtonTitles : 其他按钮的文字(设置多个)
delegate : 用来监听alertView上面按钮的点击
*/
- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /*<UIAlertViewDelegate>*/)delegate
cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
// 显示
- (void)show;
相关文章推荐
- 黑马程序员——IOS学习七:UINavigationController控件的初步——黑马 ios 技术博客
- [黑马IOS自学第一篇]IOS界面编程,IOS开发体验,控件初步认识
- 黑马程序员——IOS学习四:基础控件Label,textfield,button等使用——黑马 ios 技术博客
- 黑马程序员——IOS学习八:UITableView表视图控件初步——黑马 ios 技术博客
- 黑马程序员——IOS学习六:Date Picker, Picker View选取器控件初步——黑马 ios 技术博客
- ios iphone开发中使用UIActivityIndicatorView 控件来做等待提示。
- ios的控件的AutoresizingMask属性
- Ios 入门 ----基本的控件
- UISwitch 开关控件—IOS开发
- UIPageControl 分页控件-IOS开发
- IOS开发笔记(五)---基础控件的使用(Text Filed ,Image View,Slider等)
- UISlider 滑块控件—IOS开发
- Ios 入门 ----基本的控件 (二)
- ios控件学习 代码实现
- UITextField 文本字段控件-IOS开发
- [开源]在iOS上实现Android风格的控件Toast 推荐
- [原][学习笔记][2011.11.14] 实现ios 主要的几个控件demo
- UIControl IOS控件编程—IOS开发
- 推荐几个有用的iOS界面开源视图、控件
- Ios 入门 ----WebView 控件