UI小组件学习

UIActivityIndicatorView

    /*
     UIActivityIndicatorViewStyleWhiteLarge,
     UIActivityIndicatorViewStyleWhite,
     UIActivityIndicatorViewStyleGray,
     */
    UIActivityIndicatorView *viView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    viView.center=CGPointMake(160, 300);
    viView.color=[UIColor blueColor];
    viView.hidesWhenStopped=NO;//动画停止时是否隐藏
    [viView startAnimating];
//    [viView stopAnimating];//停止动画
    
    [self.view addSubview:viView];

UIAlertView 与 UIActionSheet

    UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"通知" message:@"明天礼拜五了,大家晚上多多努力,争取在放假前把项目上架。" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil,nil];
    
   UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:@"你确定删除么?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"其他", nil];


 下面是各自的代理:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"点击了第%d个按键",buttonIndex);
    switch (buttonIndex) {
        case 0:
            
            break;
            
        default:
            break;
    }
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSLog(@"点击了第%d个按键",buttonIndex);
    switch (buttonIndex) {
        case 0:
            
            break;
            
        default:
            break;
    }
}


UISilder

- (void)viewDidLoad
{
    [super viewDidLoad];
    //实例化
	UISlider *slide=[[UISlider alloc]initWithFrame:CGRectMake(10, 100, 300, 60)];
    //设置左侧右侧轨道的图片,ios7无效
    [slide setMinimumTrackImage:[UIImage imageNamed:@"max"] forState:UIControlStateNormal];
    [slide setMaximumTrackImage:[UIImage imageNamed:@"min"] forState:UIControlStateNormal];
    
    //设置最大最小值
    slide.minimumValue=0;
    slide.maximumValue=1;
    //设置当前值
    [slide setValue:0.7 animated:YES];
    //添加响应函数
    [slide addTarget:self action:@selector(onSliderChange:) forControlEvents:UIControlEventValueChanged];
    
    [self.view addSubview:slide];
    
    
    
    [self.progressView setProgress:0.7 animated:YES];
    
}

-(void)onSliderChange:(id)sender{
    NSLog(@"slider:%@",sender);
    UISlider *slider=sender;
    self.myView.alpha=slider.value;
    self.progressLabel.text=[NSString stringWithFormat:@"%.0f%%",slider.value*100];
    self.progressLabel.center=CGPointMake(20+280*slider.value, 100);
    
}

UISwitch

    UISwitch *mySwitch=[[UISwitch alloc]initWithFrame:CGRectMake(100, 100, 200, 50)];
    [mySwitch addTarget:self action:@selector(onSwitchChange:) forControlEvents:UIControlEventValueChanged];
    mySwitch.onTintColor=[UIColor redColor];
    mySwitch.on=NO;
    [mySwitch setOn:YES animated:YES];
    
    [self.view addSubview:mySwitch];


UITouch

#pragma mark--
#pragma mark touch事件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    //任意取出一个touch对象
    UITouch *touch = touches.anyObject;
    beginPoint = [touch locationInView:self.view];
    if (beginPoint.x<10) {
        canMove=YES;
    }else{
        canMove=NO;
    }
    NSLog(@"触摸开始 %f,%f",beginPoint.x,beginPoint.y);
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    
    UITouch *touch = touches.anyObject;
    CGPoint movePoint = [touch locationInView:self.view];
    NSLog(@"触摸滑动 %f",movePoint.x-beginPoint.x);
    if (canMove) {
        redView.frame=CGRectMake(-320+movePoint.x-beginPoint.x, 0, 320, 480);
    }
    
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"触摸结束");
    UITouch *touch = touches.anyObject;
    CGPoint endPoint = [touch locationInView:self.view];
    if ((endPoint.x-beginPoint.x)>200) {
        [UIView animateWithDuration:0.25 animations:^{
            redView.frame=CGRectMake(0, 0, 320, 480);
        }];
        
    }else{
        [UIView animateWithDuration:0.25 animations:^{
            redView.frame=CGRectMake(-320, 0, 320, 480);
        }];
    }
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"触摸取消");
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值