From 93dcedd67624adb71cd6dca6f56490dd9fffbd62 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Tue, 21 Apr 2015 22:09:40 -0700 Subject: [PATCH] iPad tweaks --- Blog.xcodeproj/project.pbxproj | 6 ++++++ Blog/AppDelegate.m | 6 ++++-- Blog/Base.lproj/Main.storyboard | 14 ++++++++------ Blog/EditorViewController.m | 16 ++++++++++++++-- Blog/PostCell.m | 24 ++++++++++++++++++++++++ Blog/UIColor+Hex.h | 11 +++++++++++ Blog/UIColor+Hex.m | 17 +++++++++++++++++ 7 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 Blog/UIColor+Hex.h create mode 100644 Blog/UIColor+Hex.m diff --git a/Blog.xcodeproj/project.pbxproj b/Blog.xcodeproj/project.pbxproj index 6b091fa..8b33400 100644 --- a/Blog.xcodeproj/project.pbxproj +++ b/Blog.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 1BCFCC637C63C780248D685E /* PostCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BCFCB5C36F301B2B93F8069 /* PostCell.m */; }; + 1BCFCD7E8EEBFAA97226B0BF /* UIColor+Hex.m in Sources */ = {isa = PBXBuildFile; fileRef = 1BCFC23988387A5CAE551C90 /* UIColor+Hex.m */; }; 30089596C2F733D451A454E8 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1613DC56A86AFA7E50460A37 /* libPods.a */; }; 7B4070531AE46BC9000C2E43 /* auth.json in Resources */ = {isa = PBXBuildFile; fileRef = 7B4070521AE46BC9000C2E43 /* auth.json */; }; 7B5C4BDF19F2606900667D48 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B5C4BDE19F2606900667D48 /* main.m */; }; @@ -42,8 +43,10 @@ /* Begin PBXFileReference section */ 1613DC56A86AFA7E50460A37 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 1BCFC23988387A5CAE551C90 /* UIColor+Hex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Hex.m"; sourceTree = ""; }; 1BCFCB5C36F301B2B93F8069 /* PostCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PostCell.m; sourceTree = ""; }; 1BCFCCF30594E0E2DCC32116 /* PostCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostCell.h; sourceTree = ""; }; + 1BCFCFA1E7D4AFDA984693E1 /* UIColor+Hex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+Hex.h"; sourceTree = ""; }; 7B4070521AE46BC9000C2E43 /* auth.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = auth.json; sourceTree = ""; }; 7B5C4BD919F2606900667D48 /* Blog.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Blog.app; sourceTree = BUILT_PRODUCTS_DIR; }; 7B5C4BDD19F2606900667D48 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -194,6 +197,8 @@ 7B9E642A1A227FA20072FF42 /* NSDate+marshmallows.m */, 7B9E642B1A227FA20072FF42 /* NSString+marshmallows.h */, 7B9E642C1A227FA20072FF42 /* NSString+marshmallows.m */, + 1BCFC23988387A5CAE551C90 /* UIColor+Hex.m */, + 1BCFCFA1E7D4AFDA984693E1 /* UIColor+Hex.h */, ); name = Categories; sourceTree = ""; @@ -416,6 +421,7 @@ 7BE3A0351AE461E700E45CCB /* PreviewViewController.m in Sources */, 7B9E644F1A23129B0072FF42 /* BlogStatus.m in Sources */, 1BCFCC637C63C780248D685E /* PostCell.m in Sources */, + 1BCFCD7E8EEBFAA97226B0BF /* UIColor+Hex.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Blog/AppDelegate.m b/Blog/AppDelegate.m index 0188c49..547a154 100644 --- a/Blog/AppDelegate.m +++ b/Blog/AppDelegate.m @@ -105,10 +105,12 @@ #pragma mark - UISplitViewDelegate methods - (BOOL)splitViewController:(UISplitViewController *)splitViewController collapseSecondaryViewController:(UIViewController *)secondaryViewController ontoPrimaryViewController:(UIViewController *)primaryViewController { - if ([secondaryViewController isKindOfClass:[UINavigationController class]] && [[(UINavigationController *)secondaryViewController topViewController] isKindOfClass:[EditorViewController class]] && ([(EditorViewController *)[(UINavigationController *)secondaryViewController topViewController] post] == nil)) { + UINavigationController *navigationController = [secondaryViewController isKindOfClass:[UINavigationController class]] ? (UINavigationController *)secondaryViewController : nil; + if ([navigationController.topViewController isKindOfClass:[EditorViewController class]] && ([(EditorViewController *)navigationController.topViewController post] == nil)) { // Return YES to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded. return YES; - } else { + } + else { return NO; } } diff --git a/Blog/Base.lproj/Main.storyboard b/Blog/Base.lproj/Main.storyboard index 491f554..320929b 100644 --- a/Blog/Base.lproj/Main.storyboard +++ b/Blog/Base.lproj/Main.storyboard @@ -157,13 +157,13 @@ - + - + @@ -171,14 +171,14 @@ @@ -187,13 +187,15 @@ - + + + diff --git a/Blog/EditorViewController.m b/Blog/EditorViewController.m index bb02cb9..fb96d9f 100644 --- a/Blog/EditorViewController.m +++ b/Blog/EditorViewController.m @@ -31,11 +31,23 @@ } - (void)configureView { + NSString *title = nil; + NSString *text = nil; + CGPoint scrollOffset = CGPointZero; if (self.post) { // FIXME: date, status (draft, published) - self.navigationItem.title = self.post.title ?: @"Untitled"; - self.textView.text = self.post.body; + title = self.post.title ?: @"Untitled"; + text = self.post.body; + // TODO: restore scroll offset for this post ... user defaults? } + self.navigationItem.title = title; + self.textView.text = text; + self.textView.contentOffset = scrollOffset; + + BOOL toolbarEnabled = self.post != nil; + [self.toolbar.items enumerateObjectsUsingBlock:^(UIBarButtonItem *item, NSUInteger idx, BOOL *stop) { + item.enabled = toolbarEnabled; + }]; } - (void)viewDidLoad { diff --git a/Blog/PostCell.m b/Blog/PostCell.m index c5aa2c3..6d40362 100644 --- a/Blog/PostCell.m +++ b/Blog/PostCell.m @@ -3,6 +3,7 @@ // Copyright (c) 2015 Guru Logic Inc. All rights reserved. // #import "PostCell.h" +#import "UIColor+Hex.h" @interface PostCell () @@ -16,6 +17,29 @@ - (void)configureWithTitle:(NSString *)title date:(NSString *)date { self.titleLabel.text = title; self.dateLabel.text = date; + // workaround for iPad bug + self.backgroundColor = [UIColor colorWithWhite:0.1333 alpha:1.0]; +} + +- (void)setSelected:(BOOL)selected animated:(BOOL)animated; +{ + UIColor *backgroundColor = [UIColor colorWithWhite:0.1333 alpha:1.0]; + UIColor *textColor = [UIColor whiteColor]; + if (selected) { + backgroundColor = [UIColor mm_colorFromInteger:0x333333]; + textColor = [UIColor mm_colorFromInteger:0xAA0000]; + } + + void (^setProperties)() = ^{ + self.backgroundColor = backgroundColor; + self.titleLabel.textColor = textColor; + }; + if (animated) { + [UIView animateWithDuration:0.3 animations:setProperties]; + } + else { + setProperties(); + } } @end \ No newline at end of file diff --git a/Blog/UIColor+Hex.h b/Blog/UIColor+Hex.h new file mode 100644 index 0000000..7420129 --- /dev/null +++ b/Blog/UIColor+Hex.h @@ -0,0 +1,11 @@ +// +// Created by Sami Samhuri on 15-04-21. +// Copyright (c) 2015 Guru Logic Inc. All rights reserved. +// +@import UIKit; + +@interface UIColor (Hex) + ++ (UIColor *)mm_colorFromInteger:(NSUInteger)color; + +@end \ No newline at end of file diff --git a/Blog/UIColor+Hex.m b/Blog/UIColor+Hex.m new file mode 100644 index 0000000..0a5aa57 --- /dev/null +++ b/Blog/UIColor+Hex.m @@ -0,0 +1,17 @@ +// +// Created by Sami Samhuri on 15-04-21. +// Copyright (c) 2015 Guru Logic Inc. All rights reserved. +// +#import "UIColor+Hex.h" + +@implementation UIColor (Hex) + ++ (UIColor *)mm_colorFromInteger:(NSUInteger)color; +{ + unsigned char red = color >> 16; + unsigned char green = (color >> 8) & 0xff; + unsigned char blue = color & 0xff; + return [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:1.0]; +} + +@end \ No newline at end of file