UISegmentedControl(分頁控制器) AND UISlider(滑塊控制器)

來源:互聯網
上載者:User

UISegmentedControl(分頁控制器) AND UISlider(滑塊控制器)

  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4. UIImageView * animatedImageView = [[UIImageView alloc]initWithFrame:CGRectMake(60, 80, 200, 300)];
  5. animatedImageView.backgroundColor = [UIColor redColor];
  6. animatedImageView.tag = 100;
  7. [self.view addSubview:animatedImageView];
  8. [animatedImageView release];
  9. NSMutableArray * arrayImages = [NSMutableArray array];
  10. for (int i = 1; i < 8; i++) {
  11. [arrayImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"huoju_%i.tiff",i]]];
  12. }
  13. // 添加要實現動畫效果的一系列圖片
  14. animatedImageView.animationImages = arrayImages;
  15. #pragma mark - 分段控制器
  16. //initWithItems:可以添加圖片或者字串
  17. UISegmentedControl * segment = [[UISegmentedControl alloc]initWithItems:@[@"statr",@"stop",@"HMT"]];
  18. segment.frame = CGRectMake(10, 20, 300, 40);
  19. // 分了幾段
  20. NSLog(@"%lu",segment.numberOfSegments);
  21. // 選中時,是一直呈現高亮狀態(NO)還是瞬間的高亮(YES)
  22. segment.momentary = YES;
  23. [segment addTarget:self action:@selector(onClickSegmentedControl:) forControlEvents:UIControlEventValueChanged];
  24. // 把下標為2的區段,設定為不可點擊
  25. [self.view addSubview:segment];
  26. [segment release];
  27. // 滑動控制器
  28. UISlider * slider = [[UISlider alloc]initWithFrame:CGRectMake(10, 500, 300, 40)];
  29. slider.maximumValue = 3;
  30. slider.minimumValue = 0.1;
  31. NSLog(@"%f",slider.value);
  32. [self.view addSubview:slider];
  33. [slider release];
  34. [slider addTarget:self action:@selector(changeSliderValue:) forControlEvents:UIControlEventValueChanged];
  35. }
  36. - (void)onClickSegmentedControl:(UISegmentedControl *)segmented{
  37. // selectedSegmentIndex
  38. if (segmented.selectedSegmentIndex == 0) {
  39. // 啟動動畫
  40. [((UIImageView *)[self.view viewWithTag:100]) startAnimating];
  41. } else {
  42. // 停止動畫
  43. [((UIImageView *)[self.view viewWithTag:100]) stopAnimating];
  44. }
  45. }
  46. - (void)changeSliderValue:(UISlider *)sLider{
  47. // 通過滑動控制項,增減速度
  48. ((UIImageView *)[self.view viewWithTag:100]).animationDuration = sLider.value;
  49. [((UIImageView *)[self.view viewWithTag:100]) startAnimating];
  50. }
  51. - (void)didReceiveMemoryWarning
  52. {
  53. [super didReceiveMemoryWarning];
  54. // Dispose of any resources that can be recreated.
  55. }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.