UISlider/UISegmentedControl/UISetpper/UISwitch/UIProgressView/UIPageControl/UIImageView

#import "BFASRootViewController.h"


@interface BFASRootViewController ()


@end


@implementation BFASRootViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}



- (void)viewDidLoad

{

    [super viewDidLoad];

    self.view.backgroundColor = [UIColor colorWithRed:0.957 green:0.879blue:0.809 alpha:1.000];

    

    

    // UISlider,滑竿对象,

    UISlider *slider = [[UISlider allocinitWithFrame:CGRectMake(2030,28020)];

    slider.value = 0.5;                     // 默认的值

    slider.minimumValue = 0.0f;             // 最小的值

    slider.maximumValue = 1.0f;             // 最大的值

    slider.minimumTrackTintColor = [UIColor yellowColor];   // 已过区域的颜色

    slider.maximumTrackTintColor = [UIColor redColor];      // 未过区域的颜色

    slider.thumbTintColor = [UIColor blueColor];            // 设置小滑块的颜色

    [slider setThumbImage:[UIImage imageNamed:@"thumb_img.png"]forState:UIControlStateNormal];             // 设置图片

    slider.minimumValueImage = [UIImage imageNamed:@"min_img.png"]; // 设置最左面的图片

    slider.maximumValueImage = [UIImage imageNamed:@"max_img.png"]; // 设置最后面的图片

    [slider addTarget:self action:@selector(sliderAction:)forControlEvents:UIControlEventValueChanged];        // slider添加监听事件

    [self.view addSubview:slider];

    [slider release];

    

    

    

    // UISegmentedControl,分段控制器

    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:@[@"聊天"@"视频"@"空间"@"微博"]];

    segmentedControl.frame = CGRectMake(208028030);

    segmentedControl.momentary = NO;                    // 当选中之后是否保持选中状态

    segmentedControl.selectedSegmentIndex = 2;          // 默认选中哪一项

    segmentedControl.tintColor = [UIColor purpleColor]; // 选中的项目的颜色

    [segmentedControl insertSegmentWithTitle:@"插入的" atIndex:0animated:YES]; // 插入一项,通过下标

    [segmentedControl addTarget:selfaction:@selector(segmentedControlAction:)forControlEvents:UIControlEventValueChanged];                    // 绑定事件

    [self.view addSubview:segmentedControl];

    [segmentedControl release];

    

    

    

    

    // UIStepper, 放大缩小按钮(大小不可更改)

    UIStepper *stepper = [[UIStepper allocinitWithFrame:CGRectMake(20,130100100)];

    stepper.minimumValue = 1;                           // 最大值

    stepper.maximumValue = 10;                          // 最小值

    stepper.value = 5;                                  // 当前值

    stepper.stepValue = 2;                              // 每次变化的值

    stepper.tintColor = [UIColor redColor];             // 颜色

    [stepper addTarget:self action:@selector(stepperAction:)forControlEvents:UIControlEventValueChanged];  // 绑定事件

    [self.view addSubview:stepper];

    [stepper release];

    

    

    

    

    // UISwitch,开关 (大小不可更改)

    UISwitch *switch1 = [[UISwitch allocinitWithFrame:CGRectMake(150130,100100)];

    switch1.On = NO;                                    // 设置默认状态

    [switch1 setOn:YES animated:YES];                   // 设置默认状态,可以选择使用动画效果

    // API:In iOS 7, this property has no effect.

    // API中说明,设置图片的属性,在iOS7

    switch1.onImage = [UIImage imageNamed:@"min_img"];  // 开启的图片

    switch1.offImage = [UIImage imageNamed:@"max_img"]; // 关闭的图片

    switch1.onTintColor = [UIColor blueColor];          // 开启的颜色

    switch1.tintColor = [UIColor redColor];             // 本身的颜色

    switch1.thumbTintColor = [UIColor brownColor];      // 块的颜色

    [switch1 addTarget:self action:@selector(switchAction:)forControlEvents:UIControlEventValueChanged];   // 绑定事件

    [self.view addSubview:switch1];

    [switch1 release];

    

    

    

    

    

    // UIProgressView,进度条

    UIProgressView *progressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];

    progressView.frame = CGRectMake(2018028035);

    progressView.progress = .5f;                            // 默认值

    progressView.progressTintColor = [UIColor yellowColor]; // 走过区域的颜色

    [progressView setProgress:0.8 animated:YES];            // 设置值,使用动画

    [self.view addSubview:progressView];

    [progressView release];

    

    

    

    

    

    // UIPageControl,小圆点提示

    UIPageControl *pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(2020028015)];

    pageControl.backgroundColor = [UIColor colorWithWhite:.5f alpha:.5f];

    pageControl.numberOfPages = 10;                         // 设置共有多少个小圆点,表示有多少个页面

    pageControl.currentPage = 3;                            // 设置当前的小圆点

    pageControl.hidesForSinglePage = YES;                   // 当只有一个小圆点的时候隐藏

    pageControl.currentPageIndicatorTintColor = [UIColor blueColor];    //当前被选中的颜色

    pageControl.pageIndicatorTintColor = [UIColor redColor];            //没有被选中的颜色

    [pageControl addTarget:self action:@selector(pageControlAction:)forControlEvents:UIControlEventValueChanged];                          // 绑定事件

    [self.view addSubview:pageControl];

    [pageControl release];

    

    

    

    

    

    // UIImageView,播放动画

    // 找到要播放的图片数组

    NSMutableArray *imagesArray = [NSMutableArray array];

    for (int i = 1; i < 5; i++) {

        // 通过名称找到图片,添加到数组中

        [imagesArray addObject:[UIImage imageNamed:[NSStringstringWithFormat:@"saisai%d.jpg", i]]];

    }

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20230280280)];

    imageView.image = [UIImage imageNamed:@"saisai1.jpg"];      // 设置显示的图片

    imageView.animationImages = imagesArray;                // 设置播放的图片数组

    imageView.animationDuration = .5f;                      // 动画时间

    [imageView startAnimating];                             // 开始播放动画

    [self.view addSubview:imageView];

    [imageView release];

    

}



#pragma mark - UISlider的绑定事件

- (void)sliderAction:(UISlider *)sender

{

    NSLog(@"%f", sender.value);

}



#pragma mark - UISegmentedControl的绑定事件

- (void)segmentedControlAction:(UISegmentedControl *)sender

{

    // 获取到选中的下标

    NSUInteger index = sender.selectedSegmentIndex;

    // 获取到选中的文字,根据下标去获取

    NSString *title = [sender titleForSegmentAtIndex:index];

    NSLog(@"%@", title);

}



#pragma mark - UISteeper的绑定事件

- (void)stepperAction:(UIStepper *)sender

{

    NSLog(@"%f", sender.value);

}



#pragma mark - UISwitch的绑定事件

- (void)switchAction:(UISwitch *)sender

{

    NSLog(@"当前状态:%@", sender.isOn == YES ? @"开启" : @"关闭");

}



#pragma mark - UIPageControl的绑定事件

- (void)pageControlAction:(UIPageControl *)sender

{

    NSLog(@"点击了第%ld个小点点", sender.currentPage);

}





@end


你可能感兴趣的:(UISlider/UISegmentedControl/UISetpper/UISwitch/UIProgressView/UIPageControl/UIImageView)