#import "MainViewController.h"
@interface MainViewController ()
@property (nonatomic,retain) UIImageView *imageView;
@end
@implementation MainViewController
- (void)dealloc
{
[_imageView release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 120, 335, 500)];
_imageView.backgroundColor = [UIColor grayColor];
[self.view addSubview:_imageView];
[_imageView release];
self.imageView.image = [UIImage imageNamed:@"Zombie0.tiff"];
// 创建一个空的可变数组
NSMutableArray *arr = [NSMutableArray array];
for (NSInteger i = 0; i < 22; i++) {
NSString *name = [NSString stringWithFormat:@"Zombie%ld.tiff",i];
UIImage *image = [UIImage imageNamed:name];
[arr addObject:image];
}
// 将图片数组给imageView赋值
self.imageView.animationImages = arr;
self.imageView.animationDuration = 0.1;
self.imageView.animationRepeatCount = 0;
[self.imageView startAnimating];
// UISlider滑动条
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(20, 70, 335, 50)];
slider.backgroundColor = [UIColor whiteColor];
[self.view addSubview:slider];
[slider release];
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
// 改变值上限
slider.maximumValue = 4;
slider.minimumValue = 0.1;
slider.value = slider.maximumValue;
// 开关
UISwitch *swith1 = [[UISwitch alloc] initWithFrame:CGRectMake(20, 120, 100, 40)];
[self.view addSubview:swith1];
[swith1 release];
[swith1 addTarget:self action:@selector(swithAction:) forControlEvents:UIControlEventValueChanged];
swith1.on = YES;
// 分段选择器
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"red",@"blue",@"yellow"]];
seg.frame = CGRectMake(20, 20, 335, 50);
seg.backgroundColor = [UIColor whiteColor];
seg.selectedSegmentIndex = 1;
[seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:seg];
[seg release];
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(255, 120, 150, 50)];
stepper.maximumValue = 100;
stepper.minimumValue = 1;
stepper.stepValue = 1;
stepper.backgroundColor = [UIColor greenColor];
[self.view addSubview:stepper];
[stepper release];
}
- (void)segAction:(UISegmentedControl *)seg
{
switch (seg.selectedSegmentIndex) {
case 0:
self.view.backgroundColor = [UIColor redColor];
break;
case 1:
self.view.backgroundColor = [UIColor blueColor];
break;
case 2:
self.view.backgroundColor = [UIColor yellowColor];
break;
default:
break;
}
}
- (void)swithAction:(UISwitch *)swith
{
if (swith.isOn) {
[self.imageView startAnimating];
}else{
[self.imageView stopAnimating];
}
}
- (void)sliderAction:(UISlider *)slider
{
// slider的值
NSLog(@"%f",slider.maximumValue - slider.value);
self.imageView.animationDuration = slider.maximumValue - slider.value + 0.1;
[self.imageView startAnimating];
}