用于 iOS 应用程序的图片库,允许以动画或用户交互的方式显示图片
最简单的方法是使用 CocoaPods。它负责所有所需的框架和第三方依赖项
pod 'MAKImageGalleryView', '~> 0.0'
@interface MAKViewController () <MAKImageGalleryViewDataSource>
@property (weak, nonatomic) IBOutlet MAKImageGalleryView *imageGalleryView;
@property (weak, nonatomic) IBOutlet MAKImageGalleryView *animatedImageGalleryView;
@end
@implementation MAKViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.imageGalleryView.imageGalleryDataSource = self;
self.animatedImageGalleryView.imageGalleryDataSource = self;
self.animatedImageGalleryView.imageChangingDelay = 3;
self.animatedImageGalleryView.changeImagesAutormatically = YES;
}
#pragma mark - MAKImageGalleryViewDataSource
- (NSInteger)numberOfImagesInGallery:(MAKImageGalleryView *)galleryView {
return 4;
}
- (UIImage *)imageInGalery:(MAKImageGalleryView *)galleryView atIndex:(NSInteger)index {
NSString *const imageName = [NSString stringWithFormat:@"image%i.jpg", index];
return [UIImage imageNamed:imageName];
}
- (UIViewContentMode)imageGallery:(MAKImageGalleryView *)galleryView contentModeForImageAtIndex:(NSInteger)index {
return UIViewContentModeScaleAspectFill;
}
@end
结果是
示例应用程序中的所有图片均来自 @diniska instagram