From 5ca61ee5d0b6439b840bca4a2c005bd6cf7a03cf Mon Sep 17 00:00:00 2001 From: Luca Mozzarelli Date: Wed, 8 Mar 2017 19:38:33 +0100 Subject: [PATCH] - Added full screen image viewer - Replaced Chamaleon Framework with ColorArt --- LMArticleViewController.podspec | 8 +++-- .../LMArticleViewController.m | 30 ++++++++++++++++--- license.txt | 21 ------------- 3 files changed, 31 insertions(+), 28 deletions(-) delete mode 100644 license.txt diff --git a/LMArticleViewController.podspec b/LMArticleViewController.podspec index 4bad56e..43c157b 100644 --- a/LMArticleViewController.podspec +++ b/LMArticleViewController.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = "LMArticleViewController" - s.version = "1.3" + s.version = "1.4" s.summary = "An Objective-C subclass of UIViewController inspired by Apple News" s.description = "This subclass of UIViewController provides an article view controller with one top image, title, date, author and body labels." @@ -14,13 +14,15 @@ Pod::Spec.new do |s| s.platform = :ios, "9.0" - s.source = { :git => "https://github.com/lucamozza/LMArticleViewController.git", :tag => 'v1.3'} + s.source = { :git => "https://github.com/lucamozza/LMArticleViewController.git", :tag => 'v1.4'} s.source_files = "LMArticleViewController", "LMArticleViewController/**/*.{h,m}" # s.exclude_files = "Classes/Exclude" # s.public_header_files = "Classes/**/*.h" - s.dependency 'ChameleonFramework' + s.dependency 'ColorArt' s.dependency 'TLYShyNavBar' + s.dependency 'IDMPhotoBrowser' + end diff --git a/LMArticleViewController/LMArticleViewController.m b/LMArticleViewController/LMArticleViewController.m index 986105d..d737097 100644 --- a/LMArticleViewController/LMArticleViewController.m +++ b/LMArticleViewController/LMArticleViewController.m @@ -8,7 +8,8 @@ #import "LMArticleViewController.h" #import -#import +#import +#import @interface LMArticleViewController () { BOOL backgroundColorSet; @@ -143,6 +144,11 @@ - (void)setupImageView { self.imageView.contentMode = self.imageViewContentMode; self.imageView.clipsToBounds = YES; + + UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openImage)]; + singleTap.numberOfTapsRequired = 1; + self.imageView.userInteractionEnabled = YES; + [self.imageView addGestureRecognizer:singleTap]; } - (void)setupHeadline { @@ -266,8 +272,12 @@ - (void)setImage:(UIImage *)image { self.heightConstraint.constant = imageViewHeight; if ( self.autoColored ) { - self.backgroundColor = [UIColor colorWithAverageColorFromImage:image]; - self.textColor = [UIColor colorWithContrastingBlackOrWhiteColorOn:self.backgroundColor isFlat:NO]; + SLColorArt *colorArt = [image colorArt]; + self.backgroundColor = colorArt.backgroundColor; + self.headlineColor = colorArt.primaryColor; + self.dateColor = colorArt.secondaryColor; + self.authorColor = colorArt.secondaryColor; + self.bodyColor = colorArt.detailColor; } } @@ -334,6 +344,11 @@ - (void)setBodyColor:(UIColor *)bodyColor { _bodyColor = bodyColor; bodyColorSet = YES; self.bodyTextView.textColor = bodyColor; + if (self.attributedBody) { + NSMutableAttributedString *mutable = self.attributedBody.mutableCopy; + [mutable addAttribute:NSForegroundColorAttributeName value:bodyColor range:NSMakeRange(0, self.attributedBody.length)]; + self.attributedBody = mutable; + } } - (void)setTextColor:(UIColor *)textColor { @@ -395,7 +410,6 @@ - (UITextView *)bodyTextView { // Animation - (void)scrollViewDidScroll:(UIScrollView *)scrollView { - if ( self.stretchImageView ) { // Animate imageview when bouncing @@ -408,6 +422,14 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { } } +- (void)openImage { + IDMPhoto *photo = [IDMPhoto photoWithImage:self.image]; + IDMPhotoBrowser *browser = [[IDMPhotoBrowser alloc]initWithPhotos:@[photo]animatedFromView:self.imageView]; + browser.scaleImage = self.image; + browser.displayActionButton = NO; + [self presentViewController:browser animated:YES completion:^{}]; +} + // Links - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange { return YES; diff --git a/license.txt b/license.txt deleted file mode 100644 index b69867e..0000000 --- a/license.txt +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Luca Mozzarelli - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE.