diff --git a/BDBSplitViewController/BDBSplitViewController.m b/BDBSplitViewController/BDBSplitViewController.m index 8c84aa6..ac30f87 100644 --- a/BDBSplitViewController/BDBSplitViewController.m +++ b/BDBSplitViewController/BDBSplitViewController.m @@ -16,6 +16,9 @@ } BDBMasterViewState; +static void * const kBDBSplitViewKVOContext = (void*)&kBDBSplitViewKVOContext; + + #pragma mark - @interface BDBSplitViewController () @@ -67,11 +70,6 @@ - (id)initWithMasterViewController:(UIViewController *)mvc detailViewController: }]; self.viewControllers = mutableViewControllers; } - - if ([dvc isKindOfClass:[BDBDetailViewController class]]) - self.delegate = (BDBDetailViewController *)dvc; - - [self.detailViewController addObserver:self forKeyPath:@"view.frame" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil]; } return self; } @@ -204,17 +202,25 @@ - (void)setViewControllers:(NSArray *)viewControllers { NSAssert(viewControllers && viewControllers.count == 2, @"viewControllers must contain a master and a detail view controller."); + self.delegate = nil; + [self.detailViewController removeObserver:self forKeyPath:@"view.frame" context:kBDBSplitViewKVOContext]; + [super setViewControllers:viewControllers]; + + [self.detailViewController addObserver:self forKeyPath:@"view.frame" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:kBDBSplitViewKVOContext]; + + UIViewController *dvc = [(UINavigationController *)viewControllers[1] topViewController]; + if ([dvc isKindOfClass:[BDBDetailViewController class]]) + self.delegate = (BDBDetailViewController *)dvc; + [self configureMasterView]; } #pragma mark Master / Detail Accessors - (UIViewController *)masterViewController { - if (self.viewControllers.count < 1) - return nil; - else - return self.viewControllers[0]; + NSAssert(self.viewControllers.count > 0, @"self.viewControllers does not conatin a master view controller."); + return self.viewControllers[0]; } - (UIViewController *)detailViewController diff --git a/SplitViewDemo.xcodeproj/project.pbxproj b/SplitViewDemo.xcodeproj/project.pbxproj index 1723079..fad81f2 100644 --- a/SplitViewDemo.xcodeproj/project.pbxproj +++ b/SplitViewDemo.xcodeproj/project.pbxproj @@ -7,7 +7,13 @@ objects = { /* Begin PBXBuildFile section */ + E8660D65182851EA0024870C /* StickyDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E8E73A86181B5E7B00F8BC1D /* StickyDetailViewController.xib */; }; + E8660D66182852010024870C /* StickyDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8C61F4518284FA200DBA379 /* StickyDetailViewController.m */; }; E8942F71181B60F500D8D423 /* SSSocialCircle.otf in Resources */ = {isa = PBXBuildFile; fileRef = E8942F6F181B60F500D8D423 /* SSSocialCircle.otf */; }; + E8C61F4418284F8800DBA379 /* StickyDetailViewController.h in Resources */ = {isa = PBXBuildFile; fileRef = E8C61F4318284F8800DBA379 /* StickyDetailViewController.h */; }; + E8C61F4818284FC600DBA379 /* NormalDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E8C61F4718284FC600DBA379 /* NormalDetailViewController.xib */; }; + E8C61F4B1828507400DBA379 /* DrawerDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8C61F4A1828507400DBA379 /* DrawerDetailViewController.m */; }; + E8C61F4D1828508400DBA379 /* DrawerDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E8C61F4C1828508400DBA379 /* DrawerDetailViewController.xib */; }; E8D1B3C1181B179900D4A6BA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8D1B3C0181B179900D4A6BA /* Foundation.framework */; }; E8D1B3C3181B179900D4A6BA /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8D1B3C2181B179900D4A6BA /* CoreGraphics.framework */; }; E8D1B3C5181B179900D4A6BA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8D1B3C4181B179900D4A6BA /* UIKit.framework */; }; @@ -16,13 +22,18 @@ E8D1B3D1181B179900D4A6BA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B3D0181B179900D4A6BA /* AppDelegate.m */; }; E8D1B3FE181B1E5400D4A6BA /* BDBSplitViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B3FD181B1E5400D4A6BA /* BDBSplitViewController.m */; }; E8D1B409181B236100D4A6BA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E8D1B400181B236100D4A6BA /* Images.xcassets */; }; - E8D1B40B181B236100D4A6BA /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B406181B236100D4A6BA /* DetailViewController.m */; }; + E8D1B40B181B236100D4A6BA /* NormalDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B406181B236100D4A6BA /* NormalDetailViewController.m */; }; E8D1B40C181B236100D4A6BA /* MasterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B408181B236100D4A6BA /* MasterViewController.m */; }; - E8E73A87181B5E7B00F8BC1D /* DetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E8E73A86181B5E7B00F8BC1D /* DetailViewController.xib */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ E8942F6F181B60F500D8D423 /* SSSocialCircle.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = SSSocialCircle.otf; sourceTree = ""; }; + E8C61F4318284F8800DBA379 /* StickyDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StickyDetailViewController.h; sourceTree = ""; }; + E8C61F4518284FA200DBA379 /* StickyDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StickyDetailViewController.m; sourceTree = ""; }; + E8C61F4718284FC600DBA379 /* NormalDetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NormalDetailViewController.xib; sourceTree = ""; }; + E8C61F491828506500DBA379 /* DrawerDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawerDetailViewController.h; sourceTree = ""; }; + E8C61F4A1828507400DBA379 /* DrawerDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DrawerDetailViewController.m; sourceTree = ""; }; + E8C61F4C1828508400DBA379 /* DrawerDetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DrawerDetailViewController.xib; sourceTree = ""; }; E8D1B3BD181B179900D4A6BA /* SplitViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SplitViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; E8D1B3C0181B179900D4A6BA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; E8D1B3C2181B179900D4A6BA /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; @@ -36,11 +47,11 @@ E8D1B3FC181B1E5400D4A6BA /* BDBSplitViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BDBSplitViewController.h; sourceTree = ""; }; E8D1B3FD181B1E5400D4A6BA /* BDBSplitViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BDBSplitViewController.m; sourceTree = ""; }; E8D1B400181B236100D4A6BA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; - E8D1B405181B236100D4A6BA /* DetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailViewController.h; sourceTree = ""; }; - E8D1B406181B236100D4A6BA /* DetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailViewController.m; sourceTree = ""; }; + E8D1B405181B236100D4A6BA /* NormalDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NormalDetailViewController.h; sourceTree = ""; }; + E8D1B406181B236100D4A6BA /* NormalDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NormalDetailViewController.m; sourceTree = ""; }; E8D1B407181B236100D4A6BA /* MasterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MasterViewController.h; sourceTree = ""; }; E8D1B408181B236100D4A6BA /* MasterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MasterViewController.m; sourceTree = ""; }; - E8E73A86181B5E7B00F8BC1D /* DetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DetailViewController.xib; sourceTree = ""; }; + E8E73A86181B5E7B00F8BC1D /* StickyDetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = StickyDetailViewController.xib; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -137,11 +148,17 @@ E8D1B404181B236100D4A6BA /* View Controllers */ = { isa = PBXGroup; children = ( - E8D1B405181B236100D4A6BA /* DetailViewController.h */, - E8D1B406181B236100D4A6BA /* DetailViewController.m */, - E8E73A86181B5E7B00F8BC1D /* DetailViewController.xib */, E8D1B407181B236100D4A6BA /* MasterViewController.h */, E8D1B408181B236100D4A6BA /* MasterViewController.m */, + E8D1B405181B236100D4A6BA /* NormalDetailViewController.h */, + E8D1B406181B236100D4A6BA /* NormalDetailViewController.m */, + E8C61F4718284FC600DBA379 /* NormalDetailViewController.xib */, + E8C61F4318284F8800DBA379 /* StickyDetailViewController.h */, + E8C61F4518284FA200DBA379 /* StickyDetailViewController.m */, + E8E73A86181B5E7B00F8BC1D /* StickyDetailViewController.xib */, + E8C61F491828506500DBA379 /* DrawerDetailViewController.h */, + E8C61F4A1828507400DBA379 /* DrawerDetailViewController.m */, + E8C61F4C1828508400DBA379 /* DrawerDetailViewController.xib */, ); path = "View Controllers"; sourceTree = ""; @@ -198,10 +215,13 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + E8660D65182851EA0024870C /* StickyDetailViewController.xib in Resources */, + E8C61F4818284FC600DBA379 /* NormalDetailViewController.xib in Resources */, E8942F71181B60F500D8D423 /* SSSocialCircle.otf in Resources */, E8D1B3CB181B179900D4A6BA /* InfoPlist.strings in Resources */, - E8E73A87181B5E7B00F8BC1D /* DetailViewController.xib in Resources */, E8D1B409181B236100D4A6BA /* Images.xcassets in Resources */, + E8C61F4418284F8800DBA379 /* StickyDetailViewController.h in Resources */, + E8C61F4D1828508400DBA379 /* DrawerDetailViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -214,9 +234,11 @@ files = ( E8D1B3D1181B179900D4A6BA /* AppDelegate.m in Sources */, E8D1B3FE181B1E5400D4A6BA /* BDBSplitViewController.m in Sources */, + E8660D66182852010024870C /* StickyDetailViewController.m in Sources */, + E8C61F4B1828507400DBA379 /* DrawerDetailViewController.m in Sources */, E8D1B40C181B236100D4A6BA /* MasterViewController.m in Sources */, E8D1B3CD181B179900D4A6BA /* main.m in Sources */, - E8D1B40B181B236100D4A6BA /* DetailViewController.m in Sources */, + E8D1B40B181B236100D4A6BA /* NormalDetailViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/SplitViewDemo/AppDelegate.m b/SplitViewDemo/AppDelegate.m index f97c63b..fc27e31 100644 --- a/SplitViewDemo/AppDelegate.m +++ b/SplitViewDemo/AppDelegate.m @@ -9,7 +9,7 @@ #import "AppDelegate.h" #import "BDBSplitViewController.h" #import "MasterViewController.h" -#import "DetailViewController.h" +#import "NormalDetailViewController.h" #pragma mark - @@ -21,7 +21,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( self.window.backgroundColor = [UIColor whiteColor]; BDBSplitViewController *splitViewController = [[BDBSplitViewController alloc] initWithMasterViewController:[MasterViewController new] - detailViewController:[[DetailViewController alloc] initWithNibName:nil bundle:nil]]; + detailViewController:[[NormalDetailViewController alloc] initWithNibName:nil bundle:nil]]; self.window.rootViewController = splitViewController; [self.window makeKeyAndVisible]; diff --git a/SplitViewDemo/View Controllers/DetailViewController.h b/SplitViewDemo/View Controllers/DrawerDetailViewController.h similarity index 83% rename from SplitViewDemo/View Controllers/DetailViewController.h rename to SplitViewDemo/View Controllers/DrawerDetailViewController.h index aa55f4b..f3cfa66 100644 --- a/SplitViewDemo/View Controllers/DetailViewController.h +++ b/SplitViewDemo/View Controllers/DrawerDetailViewController.h @@ -1,5 +1,5 @@ // -// DetailViewController.h +// DrawerDetailViewController.h // SplitViewDemo // // Created by Bradley Bergeron on 10/25/13. @@ -12,7 +12,7 @@ #pragma mark - -@interface DetailViewController : BDBDetailViewController +@interface DrawerDetailViewController : BDBDetailViewController @property (weak, nonatomic) IBOutlet UIView *labelContainerView; diff --git a/SplitViewDemo/View Controllers/DrawerDetailViewController.m b/SplitViewDemo/View Controllers/DrawerDetailViewController.m new file mode 100644 index 0000000..dbaffc2 --- /dev/null +++ b/SplitViewDemo/View Controllers/DrawerDetailViewController.m @@ -0,0 +1,67 @@ +// +// DrawerDetailViewController.m +// SplitViewDemo +// +// Created by Bradley Bergeron on 10/25/13. +// Copyright (c) 2013 Bradley Bergeron. All rights reserved. +// + +#import "DrawerDetailViewController.h" + + +#pragma mark - +@implementation DrawerDetailViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.title = @"Detail View"; + + self.splitViewController.masterViewDisplayStyle = BDBMasterViewDisplayStyleDrawer; + self.navigationItem.leftBarButtonItem = self.splitViewController.showHideMasterViewButtonItem; + + if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) + self.edgesForExtendedLayout = UIRectEdgeNone; + + UIFont *socialIconFont = [UIFont fontWithName:@"SSSocialCircle" size:self.websiteLabel.font.pointSize * 2.0]; + + NSMutableAttributedString *websiteIcon = [[NSMutableAttributedString alloc] initWithString:@"rss" + attributes:@{NSForegroundColorAttributeName:self.websiteLabel.textColor, + NSFontAttributeName:socialIconFont, + NSLigatureAttributeName:@(2)}]; + NSMutableAttributedString *twitterIcon = [[NSMutableAttributedString alloc] initWithString:@"twitter" + attributes:@{NSForegroundColorAttributeName:self.twitterLabel.textColor, + NSFontAttributeName:socialIconFont, + NSLigatureAttributeName:@(2)}]; + NSMutableAttributedString *githubIcon = [[NSMutableAttributedString alloc] initWithString:@"octocat" + attributes:@{NSForegroundColorAttributeName:self.githubLabel.textColor, + NSFontAttributeName:socialIconFont, + NSLigatureAttributeName:@(2)}]; + + NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]; + paragraphStyle.lineHeightMultiple = 0.75; + paragraphStyle.alignment = NSTextAlignmentCenter; + + NSDictionary *defaultAttributes = @{NSForegroundColorAttributeName:self.websiteLabel.textColor, + NSFontAttributeName:self.websiteLabel.font, + NSParagraphStyleAttributeName:paragraphStyle}; + + NSMutableAttributedString *websiteText = [[NSMutableAttributedString alloc] initWithString:[self.websiteLabel.text stringByReplacingOccurrencesOfString:@"website\n" withString:@"\n"] attributes:defaultAttributes]; + NSMutableAttributedString *twitterText = [[NSMutableAttributedString alloc] initWithString:[self.twitterLabel.text stringByReplacingOccurrencesOfString:@"twitter\n" withString:@"\n"] attributes:defaultAttributes]; + NSMutableAttributedString *githubText = [[NSMutableAttributedString alloc] initWithString:[self.githubLabel.text stringByReplacingOccurrencesOfString:@"github\n" withString:@"\n"] attributes:defaultAttributes]; + + [websiteText insertAttributedString:websiteIcon atIndex:0]; + [twitterText insertAttributedString:twitterIcon atIndex:0]; + [githubText insertAttributedString:githubIcon atIndex:0]; + + self.websiteLabel.attributedText = websiteText; + self.twitterLabel.attributedText = twitterText; + self.githubLabel.attributedText = githubText; + + [self.websiteLabel sizeToFit]; + [self.twitterLabel sizeToFit]; + [self.githubLabel sizeToFit]; +} + +@end diff --git a/SplitViewDemo/View Controllers/DrawerDetailViewController.xib b/SplitViewDemo/View Controllers/DrawerDetailViewController.xib new file mode 100644 index 0000000..5641207 --- /dev/null +++ b/SplitViewDemo/View Controllers/DrawerDetailViewController.xib @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SplitViewDemo/View Controllers/MasterViewController.m b/SplitViewDemo/View Controllers/MasterViewController.m index 998ec48..a433149 100644 --- a/SplitViewDemo/View Controllers/MasterViewController.m +++ b/SplitViewDemo/View Controllers/MasterViewController.m @@ -10,12 +10,6 @@ #import "BDBSplitViewController.h" -#pragma mark - -@interface MasterViewController () - -@end - - #pragma mark - @implementation MasterViewController @@ -37,13 +31,66 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 0; + return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; + UITableViewCell *cell; //= [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; + if (!cell) + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; + + switch (indexPath.row) + { + case 2: + { + cell.textLabel.text = @"Drawer Style"; + break; + } + case 1: + { + cell.textLabel.text = @"Sticky Style"; + break; + } + case 0: + default: + { + cell.textLabel.text = @"Normal Style"; + break; + } + } + return cell; } +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [self.splitViewController hideMasterViewControllerAnimated:YES completion:^{ + BDBDetailViewController *detailView; + switch (indexPath.row) + { + case 2: + { + detailView = [[NSClassFromString(@"DrawerDetailViewController") alloc] init]; + break; + } + case 1: + { + detailView = [[NSClassFromString(@"StickyDetailViewController") alloc] init]; + break; + } + case 0: + default: + { + detailView = [[NSClassFromString(@"NormalDetailViewController") alloc] init]; + break; + } + } + + UIViewController *currentDetailView = [(UINavigationController *)self.splitViewController.detailViewController topViewController]; + if (![currentDetailView isKindOfClass:[detailView class]]) + [self.splitViewController setDetailViewController:detailView]; + }]; +} + @end diff --git a/SplitViewDemo/View Controllers/NormalDetailViewController.h b/SplitViewDemo/View Controllers/NormalDetailViewController.h new file mode 100644 index 0000000..3229be0 --- /dev/null +++ b/SplitViewDemo/View Controllers/NormalDetailViewController.h @@ -0,0 +1,23 @@ +// +// NormalDetailViewController.h +// SplitViewDemo +// +// Created by Bradley Bergeron on 10/25/13. +// Copyright (c) 2013 Bradley Bergeron. All rights reserved. +// + +#import + +#import "BDBSplitViewController.h" + + +#pragma mark - +@interface NormalDetailViewController : BDBDetailViewController + + +@property (weak, nonatomic) IBOutlet UIView *labelContainerView; +@property (weak, nonatomic) IBOutlet UILabel *websiteLabel; +@property (weak, nonatomic) IBOutlet UILabel *twitterLabel; +@property (weak, nonatomic) IBOutlet UILabel *githubLabel; + +@end diff --git a/SplitViewDemo/View Controllers/DetailViewController.m b/SplitViewDemo/View Controllers/NormalDetailViewController.m similarity index 96% rename from SplitViewDemo/View Controllers/DetailViewController.m rename to SplitViewDemo/View Controllers/NormalDetailViewController.m index 0327d3d..0e57008 100644 --- a/SplitViewDemo/View Controllers/DetailViewController.m +++ b/SplitViewDemo/View Controllers/NormalDetailViewController.m @@ -1,22 +1,16 @@ // -// DetailViewController.m +// NormalDetailViewController.m // SplitViewDemo // // Created by Bradley Bergeron on 10/25/13. // Copyright (c) 2013 Bradley Bergeron. All rights reserved. // -#import "DetailViewController.h" +#import "NormalDetailViewController.h" #pragma mark - -@interface DetailViewController () - -@end - - -#pragma mark - -@implementation DetailViewController +@implementation NormalDetailViewController - (void)viewDidLoad { diff --git a/SplitViewDemo/View Controllers/DetailViewController.xib b/SplitViewDemo/View Controllers/NormalDetailViewController.xib similarity index 98% rename from SplitViewDemo/View Controllers/DetailViewController.xib rename to SplitViewDemo/View Controllers/NormalDetailViewController.xib index 1bfb75b..43f535d 100644 --- a/SplitViewDemo/View Controllers/DetailViewController.xib +++ b/SplitViewDemo/View Controllers/NormalDetailViewController.xib @@ -1,11 +1,11 @@ - + - + diff --git a/SplitViewDemo/View Controllers/StickyDetailViewController.h b/SplitViewDemo/View Controllers/StickyDetailViewController.h new file mode 100644 index 0000000..c60db4e --- /dev/null +++ b/SplitViewDemo/View Controllers/StickyDetailViewController.h @@ -0,0 +1,23 @@ +// +// StickyDetailViewController.h +// SplitViewDemo +// +// Created by Bradley Bergeron on 10/25/13. +// Copyright (c) 2013 Bradley Bergeron. All rights reserved. +// + +#import + +#import "BDBSplitViewController.h" + + +#pragma mark - +@interface StickyDetailViewController : BDBDetailViewController + + +@property (weak, nonatomic) IBOutlet UIView *labelContainerView; +@property (weak, nonatomic) IBOutlet UILabel *websiteLabel; +@property (weak, nonatomic) IBOutlet UILabel *twitterLabel; +@property (weak, nonatomic) IBOutlet UILabel *githubLabel; + +@end diff --git a/SplitViewDemo/View Controllers/StickyDetailViewController.m b/SplitViewDemo/View Controllers/StickyDetailViewController.m new file mode 100644 index 0000000..f4d55b2 --- /dev/null +++ b/SplitViewDemo/View Controllers/StickyDetailViewController.m @@ -0,0 +1,67 @@ +// +// StickyDetailViewController.m +// SplitViewDemo +// +// Created by Bradley Bergeron on 10/25/13. +// Copyright (c) 2013 Bradley Bergeron. All rights reserved. +// + +#import "StickyDetailViewController.h" + + +#pragma mark - +@implementation StickyDetailViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.title = @"Detail View"; + + self.splitViewController.masterViewDisplayStyle = BDBMasterViewDisplayStyleSticky; + self.navigationItem.leftBarButtonItem = self.splitViewController.showHideMasterViewButtonItem; + + if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) + self.edgesForExtendedLayout = UIRectEdgeNone; + + UIFont *socialIconFont = [UIFont fontWithName:@"SSSocialCircle" size:self.websiteLabel.font.pointSize * 2.0]; + + NSMutableAttributedString *websiteIcon = [[NSMutableAttributedString alloc] initWithString:@"rss" + attributes:@{NSForegroundColorAttributeName:self.websiteLabel.textColor, + NSFontAttributeName:socialIconFont, + NSLigatureAttributeName:@(2)}]; + NSMutableAttributedString *twitterIcon = [[NSMutableAttributedString alloc] initWithString:@"twitter" + attributes:@{NSForegroundColorAttributeName:self.twitterLabel.textColor, + NSFontAttributeName:socialIconFont, + NSLigatureAttributeName:@(2)}]; + NSMutableAttributedString *githubIcon = [[NSMutableAttributedString alloc] initWithString:@"octocat" + attributes:@{NSForegroundColorAttributeName:self.githubLabel.textColor, + NSFontAttributeName:socialIconFont, + NSLigatureAttributeName:@(2)}]; + + NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy]; + paragraphStyle.lineHeightMultiple = 0.75; + paragraphStyle.alignment = NSTextAlignmentCenter; + + NSDictionary *defaultAttributes = @{NSForegroundColorAttributeName:self.websiteLabel.textColor, + NSFontAttributeName:self.websiteLabel.font, + NSParagraphStyleAttributeName:paragraphStyle}; + + NSMutableAttributedString *websiteText = [[NSMutableAttributedString alloc] initWithString:[self.websiteLabel.text stringByReplacingOccurrencesOfString:@"website\n" withString:@"\n"] attributes:defaultAttributes]; + NSMutableAttributedString *twitterText = [[NSMutableAttributedString alloc] initWithString:[self.twitterLabel.text stringByReplacingOccurrencesOfString:@"twitter\n" withString:@"\n"] attributes:defaultAttributes]; + NSMutableAttributedString *githubText = [[NSMutableAttributedString alloc] initWithString:[self.githubLabel.text stringByReplacingOccurrencesOfString:@"github\n" withString:@"\n"] attributes:defaultAttributes]; + + [websiteText insertAttributedString:websiteIcon atIndex:0]; + [twitterText insertAttributedString:twitterIcon atIndex:0]; + [githubText insertAttributedString:githubIcon atIndex:0]; + + self.websiteLabel.attributedText = websiteText; + self.twitterLabel.attributedText = twitterText; + self.githubLabel.attributedText = githubText; + + [self.websiteLabel sizeToFit]; + [self.twitterLabel sizeToFit]; + [self.githubLabel sizeToFit]; +} + +@end diff --git a/SplitViewDemo/View Controllers/StickyDetailViewController.xib b/SplitViewDemo/View Controllers/StickyDetailViewController.xib new file mode 100644 index 0000000..6827d8f --- /dev/null +++ b/SplitViewDemo/View Controllers/StickyDetailViewController.xib @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file