首页 > 代码库 > UISegmentedControl(分页控制器) AND UISlider(滑块控制器)
UISegmentedControl(分页控制器) AND UISlider(滑块控制器)
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- UIImageView * animatedImageView = [[UIImageView alloc]initWithFrame:CGRectMake(60, 80, 200, 300)];
- animatedImageView.backgroundColor = [UIColor redColor];
- animatedImageView.tag = 100;
- [self.view addSubview:animatedImageView];
- [animatedImageView release];
- NSMutableArray * arrayImages = [NSMutableArray array];
- for (int i = 1; i < 8; i++) {
- [arrayImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"huoju_%i.tiff",i]]];
- }
- // 添加要实现动画效果的一系列图片
- animatedImageView.animationImages = arrayImages;
- #pragma mark - 分段控制器
- //initWithItems:可以添加图片或者字符串
- UISegmentedControl * segment = [[UISegmentedControl alloc]initWithItems:@[@"statr",@"stop",@"HMT"]];
- segment.frame = CGRectMake(10, 20, 300, 40);
- // 分了几段
- NSLog(@"%lu",segment.numberOfSegments);
- // 选中时,是一直呈现高亮状态(NO)还是瞬间的高亮(YES)
- segment.momentary = YES;
- [segment addTarget:self action:@selector(onClickSegmentedControl:) forControlEvents:UIControlEventValueChanged];
- // 把下标为2的区段,设置为不可点击
- [self.view addSubview:segment];
- [segment release];
- // 滑动控制器
- UISlider * slider = [[UISlider alloc]initWithFrame:CGRectMake(10, 500, 300, 40)];
- slider.maximumValue = 3;
- slider.minimumValue = 0.1;
- NSLog(@"%f",slider.value);
- [self.view addSubview:slider];
- [slider release];
- [slider addTarget:self action:@selector(changeSliderValue:) forControlEvents:UIControlEventValueChanged];
- }
- - (void)onClickSegmentedControl:(UISegmentedControl *)segmented{
- // selectedSegmentIndex
- if (segmented.selectedSegmentIndex == 0) {
- // 启动动画
- [((UIImageView *)[self.view viewWithTag:100]) startAnimating];
- } else {
- // 停止动画
- [((UIImageView *)[self.view viewWithTag:100]) stopAnimating];
- }
- }
- - (void)changeSliderValue:(UISlider *)sLider{
- // 通过滑动控件,增减速度
- ((UIImageView *)[self.view viewWithTag:100]).animationDuration = sLider.value;
- [((UIImageView *)[self.view viewWithTag:100]) startAnimating];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。