IPhone学习笔记四-----实现滑块和标签操作表和警报
2011-10-12 23:47
211 查看
前面用到了Image View控件和常用Lable和TextField ,Button控件。
1滑块控件
UILabel *sliderLabel;
@property (nonatomic,retain)
IBOutlet UILabel *sliderLabel;//添加对应控件输出口。
-(IBAction)silderChange:(id)sender;//滑块触发操作
实现
@synthesize sliderLabel;
-(IBAction)silderChange:(id)sender
{
UISlider *slider=(UISlider *) sender;//首先把sender转成UISlider类型
int progressAsInt=(int)(slider.value+0.5f);//接受滑块的值并加0.5f
NSString *newText =[[NSString
alloc] initWithFormat:@"%d",progressAsInt];//将滑块值存入新字符串
sliderLabel.text=newText;//将字符串赋给文本
[newText
release];
}
在视图中添加相应的滑块控件和显示滑块值的标签。设置滑块的最大值和最小值,当前值,从File‘s Owner 连接到标签(输出口),滑块事件用的是Value Changed连接到File’s OWner选择触发的方法。
2实现开关,按钮和分段按钮
#define kSwitchesSegmentIndex
0 //常量
UISwitch *leftSwitch;
//分段控件
UISwitch *rightSwitch;
UIButton *doSomethingButton; //按钮控件
@property(nonatomic,retain)IBOutlet
UISwitch *leftSwitch;
@property(nonatomic,retain)IBOutlet
UISwitch *rightSwitch;
@property(nonatomic,retain)IBOutlet
UIButton *doSomethingButton;
-(IBAction)toggleControls:(id)sender;
-(IBAction)switchChanged:(id)sender;
-(IBAction)ButtonPressed;
实现
@synthesize leftSwitch;
@synthesize rightSwitch;
@synthesize doSomethingButton;
-(IBAction)toggleControls:(id)sender//分段调用方法,是隐藏开关显示按钮,或隐藏按钮显示开关
{
if ([sender
selectedSegmentIndex]==kSwitchesSegmentIndex) {
leftSwitch.hidden=NO;
rightSwitch.hidden=NO;
doSomethingButton.hidden=YES;
}
else
{
leftSwitch.hidden=YES;
rightSwitch.hidden=YES;
doSomethingButton=NO;
}
}
-(IBAction)switchChanged:(id)sender//有开关被按下时调用,并使用该值来设置两个开关。
{
UISwitch *whichSwitch=(UISwitch *) sender;
BOOL setting =whichSwitch.isOn;
[leftSwitch
setOn:setting
animated:YES];//该方法接受两个bool值,第一个参数确定开关应该打开还是关闭。
[rightSwitch
setOn:setting
animated:YES];//第二个参数让我们指定按钮应该缓慢地滑动还是应该迅速移动到新位置。
}
-(IBAction)ButtonPressed
{
}
在视图中添加一个分段控件Segmented和两个开关控件Switch,并且把输出口连接好,因为之后会在上面用一个button控件放在上面,这样就不方便连接。
主要是要如何连接这很讲究的事。
3。操作表和警报
操作表用于迫使用户在两个或多个项之间进行选择。用户只有单击一个按钮之后才能继续使用应用程序。从屏幕底部弹出。
警报迫使用户在继续使用应用程序之前做出响应,更多地用户通知用户发生了一些重要或不正常的事情。可能显示单个按钮,但是如果多个响应更合适,也可以选择显示多个按钮。
显示操作表
-(IBAction)ButtonPressed
{
//操作表
UIActionSheet *actionSheet= [[UIActionSheet
alloc] initWithTitle:@"Are you sure?"
//显示标题
delegate:self
//委托,它将在该表上的按钮被按下时收到通知。
cancelButtonTitle:@"No Way"//取消按钮标题
destructiveButtonTitle:@"Yes,I am sure!"//继续按钮
otherButtonTitles:nil];//表单上显示的其他按钮的数量nil作为最后一个变量传递
[actionSheet
showInView:self.view];
[actionSheet
release];
}
-(void) actionsheet:(UIActionSheet *)actionSheet
didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex !=[actionSheet cancelButtonIndex]) {
NSString *msg =nil;
if(nameField.text.length>0)
msg= [[NSString
alloc]
initWithFormat:@"You can breathe easy,%@,everythihg went OK",nameField.text];
else
msg=@"You can breathe easy,everythihg went OK";
//警报的创建和使用方式
UIAlertView *alert= [[UIAlertView
alloc] initWithTitle:@"Something was done"
message:msg delegate:self
cancelButtonTitle:@"Phew!"
otherButtonTitles: nil];
[alert
show];
[alert
release];
[msg
release];
}
}
1滑块控件
UILabel *sliderLabel;
@property (nonatomic,retain)
IBOutlet UILabel *sliderLabel;//添加对应控件输出口。
-(IBAction)silderChange:(id)sender;//滑块触发操作
实现
@synthesize sliderLabel;
-(IBAction)silderChange:(id)sender
{
UISlider *slider=(UISlider *) sender;//首先把sender转成UISlider类型
int progressAsInt=(int)(slider.value+0.5f);//接受滑块的值并加0.5f
NSString *newText =[[NSString
alloc] initWithFormat:@"%d",progressAsInt];//将滑块值存入新字符串
sliderLabel.text=newText;//将字符串赋给文本
[newText
release];
}
在视图中添加相应的滑块控件和显示滑块值的标签。设置滑块的最大值和最小值,当前值,从File‘s Owner 连接到标签(输出口),滑块事件用的是Value Changed连接到File’s OWner选择触发的方法。
2实现开关,按钮和分段按钮
#define kSwitchesSegmentIndex
0 //常量
UISwitch *leftSwitch;
//分段控件
UISwitch *rightSwitch;
UIButton *doSomethingButton; //按钮控件
@property(nonatomic,retain)IBOutlet
UISwitch *leftSwitch;
@property(nonatomic,retain)IBOutlet
UISwitch *rightSwitch;
@property(nonatomic,retain)IBOutlet
UIButton *doSomethingButton;
-(IBAction)toggleControls:(id)sender;
-(IBAction)switchChanged:(id)sender;
-(IBAction)ButtonPressed;
实现
@synthesize leftSwitch;
@synthesize rightSwitch;
@synthesize doSomethingButton;
-(IBAction)toggleControls:(id)sender//分段调用方法,是隐藏开关显示按钮,或隐藏按钮显示开关
{
if ([sender
selectedSegmentIndex]==kSwitchesSegmentIndex) {
leftSwitch.hidden=NO;
rightSwitch.hidden=NO;
doSomethingButton.hidden=YES;
}
else
{
leftSwitch.hidden=YES;
rightSwitch.hidden=YES;
doSomethingButton=NO;
}
}
-(IBAction)switchChanged:(id)sender//有开关被按下时调用,并使用该值来设置两个开关。
{
UISwitch *whichSwitch=(UISwitch *) sender;
BOOL setting =whichSwitch.isOn;
[leftSwitch
setOn:setting
animated:YES];//该方法接受两个bool值,第一个参数确定开关应该打开还是关闭。
[rightSwitch
setOn:setting
animated:YES];//第二个参数让我们指定按钮应该缓慢地滑动还是应该迅速移动到新位置。
}
-(IBAction)ButtonPressed
{
}
在视图中添加一个分段控件Segmented和两个开关控件Switch,并且把输出口连接好,因为之后会在上面用一个button控件放在上面,这样就不方便连接。
主要是要如何连接这很讲究的事。
3。操作表和警报
操作表用于迫使用户在两个或多个项之间进行选择。用户只有单击一个按钮之后才能继续使用应用程序。从屏幕底部弹出。
警报迫使用户在继续使用应用程序之前做出响应,更多地用户通知用户发生了一些重要或不正常的事情。可能显示单个按钮,但是如果多个响应更合适,也可以选择显示多个按钮。
显示操作表
-(IBAction)ButtonPressed
{
//操作表
UIActionSheet *actionSheet= [[UIActionSheet
alloc] initWithTitle:@"Are you sure?"
//显示标题
delegate:self
//委托,它将在该表上的按钮被按下时收到通知。
cancelButtonTitle:@"No Way"//取消按钮标题
destructiveButtonTitle:@"Yes,I am sure!"//继续按钮
otherButtonTitles:nil];//表单上显示的其他按钮的数量nil作为最后一个变量传递
[actionSheet
showInView:self.view];
[actionSheet
release];
}
-(void) actionsheet:(UIActionSheet *)actionSheet
didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex !=[actionSheet cancelButtonIndex]) {
NSString *msg =nil;
if(nameField.text.length>0)
msg= [[NSString
alloc]
initWithFormat:@"You can breathe easy,%@,everythihg went OK",nameField.text];
else
msg=@"You can breathe easy,everythihg went OK";
//警报的创建和使用方式
UIAlertView *alert= [[UIAlertView
alloc] initWithTitle:@"Something was done"
message:msg delegate:self
cancelButtonTitle:@"Phew!"
otherButtonTitles: nil];
[alert
show];
[alert
release];
[msg
release];
}
}
相关文章推荐
- iPhone开发学习笔记007——Xcode4.2下iPhone多视图开发(自已创建MainWindow.xib和不用MainWindow.xib两种实现)
- JQuery学习笔记 实现图片翻转效果和TAB标签切换效果第1/2页
- 学习笔记---使用prototype.js扩展struts标签实现xmlhttprequest
- IPhone开发学习笔记:单例模式的实现
- JQuery学习笔记 实现图片翻转效果和TAB标签切换效果第1/2页
- iPhone开发学习笔记通过UIView实现动画效果
- iPhone开发学习笔记007——Xcode4.2下iPhone多视图开发(自已创建MainWindow.xib和不用MainWindow.xib两种实现)
- iPhone开发学习笔记007——Xcode4.2下iPhone多视图开发(自已创建MainWindow.xib和不用MainWindow.xib两种实现)
- Django学习笔记三:页面侧边栏最新文章,文章归档,分类,标签云的实现
- Spring学习笔记 关于spring 2.x中dependency-check标签与Spring3中的实现方式
- IPhone开发学习笔记:通过UIView实现动画效果
- 学习笔记_用hibernateQBC动态查询+jsp的jstl标签库实现的动态查询以及分页特效
- java学习笔记----回调的实现
- CS231n课程学习笔记(一)——KNN的实现
- Spring MVC 学习笔记8 —— 实现简单的用户管理(4)用户登录
- 【原创】Asp.Net MVC学习笔记之-使用AcceptVerbs标签来制定Action的响应行为
- OpenCV学习笔记22. 以图搜图,感知Hash的原理与实现(python/c++)
- Git 学习笔记 --- 标签管理
- 【Java学习笔记】20.Properties实现付费功能案例
- java网络编程学习笔记(四):线程池的实现