码迷,mamicode.com
首页 > 移动开发 > 详细

iOS中的分段控件(UISegmentedControl)和滑块控件(UISlider)

时间:2015-08-27 22:55:01      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

#import "RootViewController.h"
@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //分段控件
    //1.创建控件
    /*
    NSArray *items = @[@"轻拍",@"长按",@"清扫",@"平移",@"捏合",@"旋转"];
    UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:items];
    segControl.frame = CGRectMake(10, 100, 300, 30);
    [segControl addTarget:self action:@selector(handleSegControl:) forControlEvents:UIControlEventValueChanged];
    //设置默认选中的分段
    segControl.selectedSegmentIndex = 2;
    //设置分段上显示的文字
    [segControl setTitle:@"大胸美" forSegmentAtIndex:2];
    segControl.tintColor = [UIColor grayColor];
    //设置分段控件的渲染颜色
    [segControl setWidth:70 forSegmentAtIndex:2];
    //2.添加到父视图
    [self.view addSubview:segControl];
    //3.释放
    [segControl release];
    
    */
    
    
    //滑块控件
    //1.创建控件
    /*
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(10, 300, 300, 30)];
    //设置滑竿最小值
    slider.minimumValue = 0.0;
    //设置滑竿最大值
    slider.maximumValue = 1.0;
    //添加响应是事件
    [slider addTarget:self action:@selector(handleSlider:) forControlEvents:UIControlEventValueChanged];
    //设置响应事件是否在滑动的过程中连续触发
    slider.continuous = NO;
    //2.添加到父视图
    
    [self.view addSubview:slider];
    //3.释放
    [slider release];
    */
    
    //图片对象
    UIImage *image = [UIImage imageNamed:@"iphone.png"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(30, 30, 260, 260/image.size.width*image.size.height);
    
    
    //播放动态图片
    NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:1];
    for (int i = 1; i <= 30; i++) {
        NSString *imageName = [NSString stringWithFormat:@"2250_3650903_179fb89ae279fae-%d(被拖移).tiff",i];
        UIImage *image = [UIImage imageNamed:imageName];
        //iamge对象添加到imageArray上
        [imageArray addObject:image];
    }
    
    imageView.animationImages = imageArray;
    
    //设置播放一组动画的时间
    imageView.animationDuration = 0.8;
    //设置重复的次数
    //imageView.animationRepeatCount = 1;
    
    
    //2.开始播放
    [imageView startAnimating];
    //打开用户交互,默认是关闭的,UILabel的用户交互也是关闭的.
    imageView.userInteractionEnabled = YES;

    
    
    
    
    [self.view addSubview:imageView];
    [imageView release];
    
    /*
     //基本的控制对象,如按钮和滑块的基类
     UIControl
     
     
     UITextField
     UIButton
     UISegmentedControl
     UISlider
     UISwitch
     UIStepper
     UIGestureRecognizer
     */
    
    // UIResponder
    
    
    
    
    
    



}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma  滑竿响应事件
- (void)handleSlider:(UISlider *)slider
{
    NSLog(@"%.2f",slider.value);
}






#pragma mark --handle segment control
- (void)handleSegControl:(UISegmentedControl *)segmentControl{
  
    switch ( segmentControl.selectedSegmentIndex) {
        case 0:
            NSLog(@"轻拍");
            break;
        case 1:
             NSLog(@"长按");
            break;
        case 2:
             NSLog(@"清扫");
            break;
        case 3:
             NSLog(@"平移");
            break;
        case 4:
             NSLog(@"捏合");
            break;
            
        case 5:
             NSLog(@"旋转");
            break;

            
        default:
            break;
    }
}


@end

 

iOS中的分段控件(UISegmentedControl)和滑块控件(UISlider)

标签:

原文地址:http://www.cnblogs.com/wohaoxue/p/4764761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!