Skip to content

m1a7/RXLayoutGallary

Repository files navigation

RXLayoutGallary

CI Status Version License Platform

Start

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

It works with iOS 8.0 and newer. RXLayoutGallary is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'RXLayoutGallary', :git => 'https://github.com/m1a7/RXLayoutGallary.git'

RXLayoutGallary

RXLayoutGallary - This is Objective-C version fraemwork. Using the library you can add from one up to five photos. These photos will be posted of the beautiful grid.

iPhone Vertical
alt text

iPad Vertical & Horizontal
alt text

Introduction

Step 1.

Make import.

#import <RXLayoutGallary/RXLayoutGallary.h>

Step 2.

Conform to protocols.

@interface RXViewController () <RXLayoutGallaryDelegate, NYTPhotosViewControllerDelegate, NYTPhotoViewerDataSource>
...
@end

Step 3.

Add these properties . They are needed for the correct operation of the framework, which opens photos in full screen mode.

@interface RXViewController () <RXLayoutGallaryDelegate, NYTPhotosViewControllerDelegate, NYTPhotoViewerDataSource>

@property (nonatomic, strong) NSMutableArray *imageForNYTPhotosVC;
@property (nonatomic, strong) NSNumber *numberOfPhotos;
@property (nonatomic, strong) UIImageView *touchedImgView;

@end

Step 4.

Initialize and add to superview the RXLayoutGallary is comfortable for you path. You have 3 option's.

  1. Pass to RXLayoutGallary array with URLs
  2. Pass to RXLayoutGallary array with UIImage or NSData (*nsdata only for gif images )
  3. Pass to RXLayoutGallary array with UIImageView
// Init
RXLayoutGallary* gallaryURL = [[RXLayoutGallary alloc] initWithFrame:self.viewForURLGallary.bounds
andDelegate:self];

// Add to some superview
[self.viewForURLGallary addSubview:gallaryURL];
// Add pictures - Path by URL array
[gallaryURL addImageFromURL: self.urlImages];

OR

// Add pictures - Path by UIImage array
[gallaryLocalImages addUIImagesToGallary:self.localImages];

OR

// Add pictures - Path by UIImageViews array
[gallaryURL addUIImageViewsToGallary: self.localImages];

Step 5.

Implement the delegate method.

#pragma mark - GallaryViewDelegate

-(void)rxgallaryView:(RXLayoutGallary *)rxlayoutGallary didTapAtImageView:(UIImageView *)imageView atIndex:(NSUInteger)index{

    self.imageForNYTPhotosVC = [NSMutableArray new];;
    self.numberOfPhotos      = [NSNumber numberWithInteger:rxlayoutGallary.imagesArray.count];
    self.touchedImgView      = imageView;


    for (id imgFromGallary in rxlayoutGallary.imagesArray) {

        RXExamplePhoto *p = [RXExamplePhoto new];
        p.attributedCaptionTitle  = [RXViewController attributedTitleFromString:@"Chess"];
        p.attributedCaptionCredit = [RXViewController attributedCreditFromString:@"Photo: Chris Dzombak"];

        if ([imgFromGallary isMemberOfClass:[UIImageView class]])
        {
            UIImageView* imgView = (UIImageView*)imgFromGallary;
            [self.imageForNYTPhotosVC addObject:({
                p.image = imgView.image;
                p;
            })];
        }
        if ([imgFromGallary isMemberOfClass:[FLAnimatedImageView class]])
        {
            FLAnimatedImageView* flaImgView = (FLAnimatedImageView*)imgFromGallary;
            [self.imageForNYTPhotosVC addObject:({
                p.imageData = flaImgView.animatedImage.data;
                p;
            })];
        }
    }
    NYTPhotosViewController* vc = [[NYTPhotosViewController alloc] initWithDataSource:self
                                                                    initialPhotoIndex:index
                                                                             delegate:self];

    [self presentViewController:vc animated:YES completion:nil];
}

If you want, you can conform methods: They are need for most productive work with TableView. You should store in your controller or viewmodel cache property, then images will until upload from local cache.

-(NSData*) getDataFromCacheByURL:(NSString*) urlStr;
-(void) writeToCacheData:(NSData*) data urlKey:(NSString*) key;
-(NSOperationQueue*) getOperationQueue;

Step 6.

Implement the delegate methods.

#pragma mark - NYTPhotoViewerDataSource

- (NSInteger)indexOfPhoto:(id <NYTPhoto>)photo {
    return [self.imageForNYTPhotosVC indexOfObject:photo];
}

- (nullable id <NYTPhoto>)photoAtIndex:(NSInteger)photoIndex
{
    if (self.imageForNYTPhotosVC.count > photoIndex){
        return [self.imageForNYTPhotosVC objectAtIndex:photoIndex];
    }
    return  nil;
}

Step 7. - Optional

Implement the delegate and helpers methods .

#pragma mark - NYTPhotosViewControllerDelegate

- (UIView *)photosViewController:(NYTPhotosViewController *)photosViewController referenceViewForPhoto:(id <NYTPhoto>)photo {
    return self.touchedImgView;
}

#pragma mark - Helpers

+ (NSAttributedString *)attributedTitleFromString:(NSString *)caption {
    return [[NSAttributedString alloc] initWithString:caption
                                            attributes: @{NSForegroundColorAttributeName: [UIColor whiteColor],
                                                        NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]}];
}
+ (NSAttributedString *)attributedSummaryFromString:(NSString *)summary {
        return [[NSAttributedString alloc] initWithString:summary
                                               attributes:@{NSForegroundColorAttributeName: [UIColor lightGrayColor],
                                                NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]}];
}

+ (NSAttributedString *)attributedCreditFromString:(NSString *)credit {
        return [[NSAttributedString alloc] initWithString:credit
                                               attributes:@{NSForegroundColorAttributeName: [UIColor grayColor],
                                               NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]}];
}

Profit !!!!

Author

m1a7, thisismymail03@gmail.com

License

RXLayoutGallary is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published