UISegmentedControl (paging Controller) AND UISlider (slider Controller)

Source: Internet
Author: User

UISegmentedControl (paging Controller) AND UISlider (slider Controller)

  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. // Add a series of images to achieve the animation effect
  14. AnimatedImageView. animationImages = arrayImages;
  15. # Pragma mark-segment controller
  16. // InitWithItems: You can add images or strings.
  17. UISegmentedControl * segment = [[UISegmentedControl alloc] initWithItems: @ [@ "statr", @ "stop", @ "HMT"];
  18. Segment. frame = CGRectMake (10, 20,300, 40 );
  19. // Segment
  20. NSLog (@ "% lu", segment. numberOfSegments );
  21. // Whether to display the highlighted state (NO) or instantly highlighted (YES) at the time of Selection)
  22. Segment. momentary = YES;
  23. [Segment addTarget: self action: @ selector (onClickSegmentedControl :) forControlEvents: UIControlEventValueChanged];
  24. // Set the section with the subscript of 2 to not clickable
  25. [Self. view addSubview: segment];
  26. [Segment release];
  27. // Sliding Controller
  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. // Start the animation
  40. [(UIImageView *) [self. view viewWithTag: 100]) startAnimating];
  41. } Else {
  42. // Stop the animation
  43. [(UIImageView *) [self. view viewWithTag: 100]) stopAnimating];
  44. }
  45. }
  46. -(Void) changeSliderValue :( UISlider *) sLider {
  47. // Increase or decrease the speed through the sliding control
  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. }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.