https://github.com/mwaterfall/MWPhotoBrowser
mwphotobrowser可以通過提供uiimage對象顯示一個或多個圖像,或URL的Web圖像文件,或圖書館資產。照片處理下載和緩存瀏覽器從Web照片無縫。照片可以放大和平移,和可選的標題可以顯示(可定制)。
瀏覽器也可以用於允許用戶選擇一個或更多的照片可以使用網格或主視圖。
- (void)viewDidLoad
{
[super viewDidLoad];
// Browser
NSMutableArray *photos = [[NSMutableArray alloc] init];
NSMutableArray *thumbs = [[NSMutableArray alloc] init];
MWPhoto *photo;
BOOL displayActionButton = NO;
BOOL displaySelectionButtons = NO;
BOOL displayNavArrows = NO;
BOOL enableGrid = YES;
BOOL startOnGrid = NO;
// Photos
photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo5" ofType:@"jpg"]]];
photo.caption = @"Fireworks";
[photos addObject:photo];
photo = [MWPhoto photoWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"photo2" ofType:@"jpg"]]];
photo.caption = @"The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England.";
[photos addObject:photo];
photo = [MWPhoto photoWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"photo3" ofType:@"jpg"]]];
photo.caption = @"York Floods";
[photos addObject:photo];
photo = [MWPhoto photoWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"photo4" ofType:@"jpg"]]];
photo.caption = @"Campervan";
[photos addObject:photo];
// Options
self.photos = photos;
self.thumbs = thumbs;
//
// Create browser
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
browser.displayActionButton = displayActionButton;//分享按鈕,默認是
browser.displayNavArrows = displayNavArrows;//左右分頁切換,默認否
browser.displaySelectionButtons = displaySelectionButtons;//是否顯示選擇按鈕在圖片上,默認否
browser.alwaysShowControls = displaySelectionButtons;//控制條件控件 是否顯示,默認否
browser.zoomPhotosToFill = NO;//是否全屏,默認是
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
browser.wantsFullScreenLayout = YES;//是否全屏
#endif
browser.enableGrid = enableGrid;//是否允許用網格查看所有圖片,默認是
browser.startOnGrid = startOnGrid;//是否第一張,默認否
browser.enableSwipeToDismiss = YES;
[browser showNextPhotoAnimated:YES];
[browser showPreviousPhotoAnimated:YES];
[browser setCurrentPhotoIndex:1];
browser.photoTitles = @[@"000",@"111",@"222",@"333"];//標題
// [self presentViewController:browser animated:YES completion:nil];
[self.navigationController pushViewController:browser animated:NO];
}
#pragma mark - MWPhotoBrowserDelegate
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
return _photos.count;
}
- (id )photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
if (index < _photos.count)
return [_photos objectAtIndex:index];
return nil;
}
個人建議仔細看一下MWPhotoBrowser的各種屬性,會幫助你更快的掌握MWPhotoBrowser的使用,,,