<AppDelegate.m>
#import "AppDelegate.h" #import "RootViewController.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; RootViewController *rootVC = [[RootViewController alloc ]init ]; self.window.rootViewController = rootVC; [rootVC release]; return YES; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end
<RootViewController.h>
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController @end
<RootViewController.m>
</pre><pre name="code" class="objc">#import "RootViewController.h" @interface RootViewController () @property (nonatomic,retain)UIImageView *imageView; @property (nonatomic,retain)UISlider *slider; @end @implementation RootViewController -(void)dealloc { self.imageView = nil; self.slider = nil; [super dealloc]; } - (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. //布局 ImageView [self layoutImageView]; //布局 slider [self layoutSlider]; } //布局 ImageView -(void)layoutImageView { self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 50, 120, 200)]; //配置属性 //添加一张图片 _imageView.image = [UIImage imageNamed:@"01.tiff"]; //制作动画 //创建图片组 NSMutableArray *photos = [NSMutableArray array]; for (int i = 1; i < 41; i++) { //创建 image 对象 UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"03-%d(被拖移).tiff",i]]; //添加到数组中 [photos addObject:image]; } //设置所要播放动画的图片组 _imageView.animationImages = photos; //设置播放的时间 _imageView.animationDuration = 5; //设置重复次数 _imageView.animationRepeatCount = 5; //开始动画 [_imageView startAnimating]; [self.view addSubview:_imageView]; [_imageView release]; } //布局 slider -(void)layoutSlider { //创建 UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 300, 220, 30)]; //配置属性 slider.backgroundColor = [UIColor redColor]; //设置渲染颜色 tintcolor slider.tintColor = [UIColor yellowColor]; //设置滑块划过的区域的颜色 slider.minimumTrackTintColor = [UIColor greenColor]; //tintColor和minimumTrackTintColor 实现的效果是一样的,只是方法在继承上是不一样的 //设置滑块未划过区域的颜色 slider.maximumTrackTintColor = [UIColor yellowColor]; //设置最小值和最大值 如果不设置最大和最小值的话默认最小为0 最大为1 slider.maximumValue = 2; slider.minimumValue = 0; //添加事件 [slider addTarget:self action:@selector(changeSpeed:) forControlEvents:UIControlEventValueChanged]; //把设置的动画播放时间赋给 slider 的值 slider.value = _imageView.animationDuration; <pre name="code" class="objc"> //在拖动滑块的任何时候,滑块的值都会改变,默认为yes slider.continuous = YES; //滑块条最小值处设置的图片,默认为nil slider.minimumValueImage = [UIImage imageNamed:@"01.tiff"]; //滑块条最大值处设置的图片,默认为nil slider.maximumValueImage = [UIImage imageNamed:@"01.tiff"]; //滑块的颜色 slider.thumbTintColor = [UIColor redColor]; //读取当前最大最小处的图片,滑块颜色,只读属性 slider.currentMinimumTrackImage; slider.currentMaximumTrackImage; slider.currentThumbImage;
图片资源如图: