Ios 入门 ----基本的控件 (一)

来源:互联网 发布:沈晓海花姑子知乎 编辑:程序博客网 时间:2024/05/17 23:06
1.UIAlertView的实现:
 

效果如下图:
 

 
2.UIActionSheet 的实现
 UIActionSheet和UIAlertView的区别 都是用于给用户提示操作 而UIActionSheet是从底部弹出 当用户有危险操作时用来提示 例如用户删除某个文件就可以用UIActionSheet提示用户是否确认删除
 

 

 

首先.h文件要实现UIActionSheetDelegate 并且实现Delegate中的方法:
actionSheet:didDismissWithButtonIndex 方法
这个方法当你点击摸个按钮时会自动触发 上面代码中点击cancel这个按钮时 文字将变成空;
效果如图:
 

 
3.两个等待控件UIActionIndicatorView 和 UIProgressView
我们来做一个小程序来实现他俩的功能
需求:点击按钮 进度条开始前进 进度条走完弹出 安装对话框 点击安装 UIActionIndicatorView开始旋转
界面如下:
 

.h代码
@interface seek : UIViewController <UIActionSheetDelegate> {
   
    UIActivityIndicatorView *seekbar;
    UIProgressView *probar;
    NSTimer * time;
}
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *seekbar;
@property (nonatomic, retain) IBOutlet UIProgressView *probar;
@property (nonatomic, retain)NSTimer * time;
- (IBAction)downLond:(id)sender;
 
@end
 
.m代码
- (IBAction)downLond:(id)sender {
    probar.progress=0.0;
    time=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateinstall) userInfo:nil repeats:YES];
 
   
}
 
-(void)updateinstall{
    probar.progress=probar.progress+0.1;
    if(probar.progress==1.0){
        [time invalidate];
        UIActionSheet * actionSheet =[[UIActionSheet alloc]initWithTitle:@"Install" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Install" otherButtonTitles:nil, nil];
        [actionSheet showInView:self.view];
        [actionSheet release];
    }
}
 
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
    if (buttonIndex==[actionSheet destructiveButtonIndex]) {
        if ([seekbar isAnimating]) {
            [seekbar stopAnimating];
        }else {
            [seekbar startAnimating];
        }
    }
   
}
 
NSTimer是可以隐式地启动一个线程,
scheduledTimerWithTimeInterval指定线程要休眠
多少时间调用一次,selector所指定的方法updateinstall
 
运行效果如下:
 
 

 

 

原创粉丝点击