IOS的按钮的使用
在IOS上使用按钮控件特别简单,而且有很多非常绚丽的效果
首先我们来看两张图片第一张是通过上面的按钮控制下面的两个按钮是否可以的情况
对按钮的设置特别简单,只要操作公具就可以完成上面的效果
上面的Show Touch On Highlight 属性是设置按钮是否在点击的时候有高亮的效果
下面来看看按钮的状态切换是如何实现的
ViewController.h
@interface ViewController : UIViewController{
IBOutlet UIButton * clearButton;
IBOutlet UIButton * smallButton;
}
@property(nonatomic,retain)UIButton * clearButton;
@property(nonatomic,retain)UIButton * smallButton;
-(IBAction)disableBut:(id)sender;
@end
ViewController.m
@implementation ViewController
@synthesize clearButton;
@synthesize smallButton;
-(IBAction)disableBut:(id)sender{
if (clearButton.enabled == YES) {
clearButton.enabled = NO;
smallButton.enabled = NO;
[((UIButton *) sender) setTitle:@"Enable" forState:(UIControlStateNormal)];
}else{
clearButton.enabled = YES;
smallButton.enabled = YES;
[((UIButton *) sender) setTitle:@"Disable" forState:(UIControlStateNormal)];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc
{
[clearButton release];
[smallButton release];
[super dealloc];
}
@end
[((UIButton *) sender) setTitle:@"Enable" forState:(UIControlStateNormal)];
这一句中的forState属性中的选择有多个是一个枚举类型的变量具体的选择如下(出自帮助文档)
IOS的开关的使用
IOS的滑块的使用
注意:判断滑块的最大值
IOS的分段控件的使用
分段控件的使用基本与前面的控件相同
在使用时如何获得控件的那一段被选中
方法
-(IBAction)handleSegment:(id)sender{
UISegmentedControl * myseg = (UISegmentedControl * )sender;
//通过myseg.selectedSegmentIndex对象的这个属性来判断是控件的那一段被选中
}
IOS的工具栏的使用
工具栏的使用也特别方便如下图就可以看出工具栏的使用
注意和工具栏配合使用的控件有如下