美文网首页iOS 实际项目出现的问题
图片浏览(双击放大,单击返回)

图片浏览(双击放大,单击返回)

作者: 江河_ios | 来源:发表于2017-12-25 09:42 被阅读16次

    一个简单实用的图片浏览器,效果类似微信图片浏览器,支持多图浏览,支持本地和网络图片浏览简单介绍一下第三方类: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;

    }

    相关文章

      网友评论

        本文标题:图片浏览(双击放大,单击返回)

        本文链接:https://www.haomeiwen.com/subject/kagkgxtx.html