#import "MainViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// 1.分段控件(UISegmentedControl)
UISegmentedControl *segmented = [[UISegmentedControl alloc]initWithItems:@[@"伊泽瑞尔", @"德邦总管", @"嘉文四世"]];
//给segmentedControl绑定方法
[segmented addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
//改变segmented的颜色
[segmented setTintColor:[UIColor grayColor]];
[self.view addSubview:segmented];
//滑动控件
UISlider *slider = [[UISlider alloc]initWithFrame:CGRectMake(20, 470, 260, 40)];
[self.view addSubview:slider];
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[slider release];
//设置silder 的最大值/最小值
[slider setMaximumValue:100];
[slider setMinimumValue:0];
//利用UIImageView播放Gif图片
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 200, 200, 200)];
// [imageView setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:imageView];
[imageView release];
//产生一组图片
NSMutableArray *imageArray = [NSMutableArray array];
for (int i = 0; i < 22; i++) {
//按顺序产生数组
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"Zombie%d.tiff", i + 1]];
//把图片添加到数组中
[imageArray addObject:image];
}
//将图片数组给imageView等待播放
imageView.animationImages = imageArray;
//播放速度
imageView.animationDuration = 0.00001;//播放一遍所需要的时间
//播放次数
imageView.animationRepeatCount = 0;
//播放
[imageView startAnimating];
//播放次数
UIStepper *stepper = [[UIStepper alloc]initWithFrame:CGRectMake(220, 220, 120, 40)];
[stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:stepper];
[stepper setMaximumValue:100];
[stepper setMinimumValue:0];
[stepper release];
UISwitch *swich = [[UISwitch alloc]initWithFrame:CGRectMake(20, 220, 120, 40)];
[swich addTarget:self action:@selector(swichAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:swich];
[swich release];
//设置背景图片
//[segmented setBackgroundImage:[UIImage imageNamed:@"伊泽.jpg"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
segmented.frame = CGRectMake(20, 40, 280, 40);
[segmented release];
}
- (void)swichAction:(UISwitch *)swich
{
NSLog(@"关/开");
}
- (void)stepperAction:(UIStepper *)stepper
{
NSLog(@"增/减");
NSLog(@"增/减%f", stepper.value);
}
- (void)sliderAction:(UISlider *)slider
{
//slider.value 当前滑动到得值
NSLog(@"滑动%f", slider.value);
NSLog(@"滑动");
}
- (void)segmentedAction:(UISegmentedControl *)seg
{
//通过点击下标判断
if (seg.selectedSegmentIndex == 0) {
NSLog(@"是时候表演真正的技术了");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://15542470822"]];//打电话 发短信 打开网页 发邮件等
}
if (seg.selectedSegmentIndex == 1) {
NSLog(@"这就是我德邦总管赵兴");
}
if (seg.selectedSegmentIndex == 2)
NSLog(@"德玛西亚");
//插入一个分段
// [seg insertSegmentWithTitle:@"皮城女警" atIndex:0 animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end