To run the example project, clone the repo, and run pod install
from the Example directory first.
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 - 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 |
---|
iPad Vertical & Horizontal |
---|
Make import.
#import <RXLayoutGallary/RXLayoutGallary.h>
Conform to protocols.
@interface RXViewController () <RXLayoutGallaryDelegate, NYTPhotosViewControllerDelegate, NYTPhotoViewerDataSource>
...
@end
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
Initialize and add to superview the RXLayoutGallary is comfortable for you path. You have 3 option's.
- Pass to RXLayoutGallary array with URLs
- Pass to RXLayoutGallary array with UIImage or NSData (*nsdata only for gif images )
- 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];
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;
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;
}
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]}];
}
m1a7, thisismymail03@gmail.com
RXLayoutGallary is available under the MIT license. See the LICENSE file for more info.