Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> UISegmentedControl(分頁控制器) AND UISlider(滑塊控制器)

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

編輯:關於Android編程

  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. }
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved