MWPhotoBrowser的简单使用

MWPhotoBrowser的简单使用

最近做的项目有类似朋友圈动态的功能,其中需求点击图片可以浏览。然后就用了下MWPhotoBrowser这个第三方图片浏览器,感觉很不错。

MWPhotoBrowser 的github链接 https://github.com/mwaterfall/MWPhotoBrowser


1、 创建MWPhotoBrowser

要使用initWithDelegate方法,要遵循MWPhotoBrowserDelegate协议

    //创建MWPhotoBrowser ,要使用initWithDelegate方法,要遵循MWPhotoBrowserDelegate协议
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    
    //设置当前要显示的图片
    [browser setCurrentPhotoIndex:indexPath.item];
    
    //push到MWPhotoBrowser
    [self.navigationController pushViewController:browser animated:YES];

2、实现代理

//返回图片个数
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{    
    return count;
}

//返回图片模型
- (id )photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{

    //创建图片模型
    MWPhoto *photo = [MWPhoto photoWithURL:photoUrl];
    
    return photo;

}

大功告成恭喜你已经集成了一个很好用的图片浏览器啦。
其实 MWPhotoBrowser还有其他很多很好用的功能。

例如:

  • 播放视频
  • 已九宫格的方式显示图片阵列
  • 分享
  • 图片选择器

如果需要这些功能直接到 [MWPhotoBrowser]的gith地址看吧 https://github.com/mwaterfall/MWPhotoBrowser。不过纯英文,会有点儿压力。

你可能感兴趣的:(MWPhotoBrowser的简单使用)