以前我们做轮播图的时候一般都用NSTimer和UIScrollowView,现在我发现其实使用UIImageView也是能实现的,还更简单了!
代码如下:
@interface ViewController (){
NSArray *images;
}
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//如果要做轮播图效果,下面的图片就区网络中取
images=[NSArray arrayWithObjects:[UIImage imageNamed:@"Tutorial_p1.png"],[UIImage imageNamed:@"Tutorial_p2.png"],[UIImage imageNamed:@"Tutorial_p3.png"],[UIImage imageNamed:@"Tutorial_p4.png"],[UIImage imageNamed:@"Tutorial_p5.png"],[UIImage imageNamed:@"Tutorial_p6.png"],[UIImage imageNamed:@"Tutorial_p7.png"],[UIImage imageNamed:@"Tutorial_p8.png"],[UIImage imageNamed:@"Tutorial_p9.png"], nil];
self.myImageView.contentMode=UIViewContentModeScaleAspectFill;
//加载图片数组
//self.myImageView.animationImages=images;
self.myImageView.animationImages=images;
//重复次数如果要实现无穷循环播放可以把值设置成HUGE_VALF
self.myImageView.animationRepeatCount=5;
//持续时间
self.myImageView.animationDuration=10;
[self.myImageView startAnimating];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)stopAction:(id)sender {
[self.myImageView stopAnimating];
}
本文介绍了一种使用UIImageView实现轮播图效果的方法,通过设置图片数组、动画重复次数及持续时间等属性,使得轮播图的实现更为简便。
206

被折叠的 条评论
为什么被折叠?



