图片浏览(双击放大,单击返回)
一个简单实用的图片浏览器,效果类似微信图片浏览器,支持多图浏览,支持本地和网络图片浏览简单介绍一下第三方类:YXBPhotoBrowser 如何添加到项目不再介绍.......
代码如下:
#import "ViewController.h"#import "Masonry.h"#import "YXBPhotoBrowser.h"@interface ViewController ()@property(nonatomic,strong)NSMutableArray *photoArray;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor=[UIColor whiteColor];
[self ImageBrowsingAddButton];
[self showPhotoArray];
}
#pragma mark === 图片浏览
-(void)ImageBrowsingAddButton
{
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"图片浏览" forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
button.backgroundColor=[UIColor yellowColor];
[button sizeToFit];
[button addTarget:self action:@selector(onLookPhotoButton) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(100);
make.left.mas_equalTo(100);
make.size.mas_equalTo(CGSizeMake(100, 40));
}];
}
-(void)onLookPhotoButton
{
[YXBPhotoBrowser showInWindow:[UIApplication sharedApplication].keyWindow withDelegate:self imageCount:self.photoArray.count currnetIndex:3];
}
#pragma mark ==== 设置图片的浏览
-(void)showPhotoArray
{
for (int i =0; i<6; i++) {
UIImage *img=[UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1 ]];
[self.photoArray addObject:img];
}
}
-(NSMutableArray *)photoArray
{
if (!_photoArray) {
_photoArray=[[NSMutableArray alloc]init];
}
return _photoArray;
}
#pragma mark === 图片
- (UIImage *)photoBrowser:(YXBPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index{
return self.photoArray[index];
}
#pragma mark === 查看高清图片
- (NSURL *)photoBrowser:(YXBPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index{
return [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%ld",index+1] ofType:@"png"]];
}
- (UIView *)photoBrowser:(YXBPhotoBrowser *)browser containerViewForIndex:(NSInteger)index{
return nil;
}