MWPhotoBrowser的簡(jiǎn)單使用
最近做的項(xiàng)目有類似朋友圈動(dòng)態(tài)的功能,其中需求點(diǎn)擊圖片可以瀏覽。然后就用了下MWPhotoBrowser這個(gè)第三方圖片瀏覽器,感覺很不錯(cuò)。
MWPhotoBrowser 的github鏈接 https://github.com/mwaterfall/MWPhotoBrowser
1、 創(chuàng)建MWPhotoBrowser
要使用initWithDelegate方法,要遵循MWPhotoBrowserDelegate協(xié)議
//創(chuàng)建MWPhotoBrowser ,要使用initWithDelegate方法,要遵循MWPhotoBrowserDelegate協(xié)議
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
//設(shè)置當(dāng)前要顯示的圖片
[browser setCurrentPhotoIndex:indexPath.item];
//push到MWPhotoBrowser
[self.navigationController pushViewController:browser animated:YES];
2、實(shí)現(xiàn)代理
//返回圖片個(gè)數(shù)
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{
return count;
}
//返回圖片模型
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
//創(chuàng)建圖片模型
MWPhoto *photo = [MWPhoto photoWithURL:photoUrl];
return photo;
}
大功告成恭喜你已經(jīng)集成了一個(gè)很好用的圖片瀏覽器啦。
其實(shí) MWPhotoBrowser還有其他很多很好用的功能。
例如:
- 播放視頻
- 已九宮格的方式顯示圖片陣列
- 分享
- 圖片選擇器
如果需要這些功能直接到 [MWPhotoBrowser]的gith地址看吧 https://github.com/mwaterfall/MWPhotoBrowser。不過純英文,會(huì)有點(diǎn)兒壓力。