Skip to content

Commit

Permalink
Merge pull request #49 from grantjbutler/gjb/bar-button-items
Browse files Browse the repository at this point in the history
Allow setting multiple bar button items for a side
  • Loading branch information
cdzombak committed May 1, 2015
2 parents 0a3d13e + f34e7bc commit 2fd86f5
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Example/Tests/NYTPhotosViewControllerTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ - (void)testLeftBarButtonItemIsNilAfterSettingToNil {
XCTAssertNil(photosViewController.leftBarButtonItem);
}

- (void)testLeftBarButtonItemsArePopulatedAfterInitialization {
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:[self newTestPhotos]];
XCTAssertNotNil(photosViewController.leftBarButtonItems);
}

- (void)testLeftBarButtonItemsAreNilAfterSettingToNil {
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:[self newTestPhotos]];
photosViewController.leftBarButtonItems = nil;
XCTAssertNil(photosViewController.leftBarButtonItems);
}

- (void)testRightBarButtonItemIsPopulatedAfterInitialization {
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:[self newTestPhotos]];
XCTAssertNotNil(photosViewController.rightBarButtonItem);
Expand All @@ -98,6 +109,17 @@ - (void)testRightBarButtonItemIsNilAfterSettingToNil {
XCTAssertNil(photosViewController.rightBarButtonItem);
}

- (void)testRightBarButtonItemsArePopulatedAfterInitialization {
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:[self newTestPhotos]];
XCTAssertNotNil(photosViewController.rightBarButtonItems);
}

- (void)testRightBarButtonItemsAreNilAfterSettingToNil {
NYTPhotosViewController *photosViewController = [[NYTPhotosViewController alloc] initWithPhotos:[self newTestPhotos]];
photosViewController.rightBarButtonItems = nil;
XCTAssertNil(photosViewController.rightBarButtonItems);
}

- (void)testConvenienceInitializerAcceptsNil {
XCTAssertNoThrow([[NYTPhotosViewController alloc] initWithPhotos:nil]);
}
Expand Down
10 changes: 10 additions & 0 deletions Pod/Classes/ios/NYTPhotosOverlayView.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,21 @@
*/
@property (nonatomic) UIBarButtonItem *leftBarButtonItem;

/**
* The bar button items appearing at the top left of the overlay.
*/
@property (nonatomic, copy) NSArray *leftBarButtonItems;

/**
* The bar button item appearing at the top right of the overlay.
*/
@property (nonatomic) UIBarButtonItem *rightBarButtonItem;

/**
* The bar button items appearing at the top right of the overlay.
*/
@property (nonatomic, copy) NSArray *rightBarButtonItems;

/**
* A view representing the caption for the photo, which will be set to full width and locked to the bottom. Can be any `UIView` object, but is expected to respond to `intrinsicContentSize` appropriately to calculate height.
*/
Expand Down
18 changes: 17 additions & 1 deletion Pod/Classes/ios/NYTPhotosOverlayView.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,28 @@ - (void)setLeftBarButtonItem:(UIBarButtonItem *)leftBarButtonItem {
[self.navigationItem setLeftBarButtonItem:leftBarButtonItem animated:NO];
}

- (NSArray *)leftBarButtonItems {
return self.navigationItem.leftBarButtonItems;
}

- (void)setLeftBarButtonItems:(NSArray *)leftBarButtonItems {
[self.navigationItem setLeftBarButtonItems:leftBarButtonItems animated:NO];
}

- (UIBarButtonItem *)rightBarButtonItem {
return self.navigationItem.rightBarButtonItem;
}

- (void)setRightBarButtonItem:(UIBarButtonItem *)rightBarButtonItem {
[self.navigationItem setRightBarButtonItem:rightBarButtonItem];
[self.navigationItem setRightBarButtonItem:rightBarButtonItem animated:NO];
}

- (NSArray *)rightBarButtonItems {
return self.navigationItem.rightBarButtonItems;
}

- (void)setRightBarButtonItems:(NSArray *)rightBarButtonItems {
[self.navigationItem setRightBarButtonItems:rightBarButtonItems animated:NO];
}

- (NSString *)title {
Expand Down
10 changes: 10 additions & 0 deletions Pod/Classes/ios/NYTPhotosViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@ extern NSString * const NYTPhotosViewControllerDidDismissNotification;
*/
@property (nonatomic) UIBarButtonItem *leftBarButtonItem;

/**
* The left bar button items overlaying the photo.
*/
@property (nonatomic, copy) NSArray *leftBarButtonItems;

/**
* The right bar button item overlaying the photo.
*/
@property (nonatomic) UIBarButtonItem *rightBarButtonItem;

/**
* The right bar button items overlaying the photo.
*/
@property (nonatomic, copy) NSArray *rightBarButtonItems;

/**
* The object that acts as the delegate of the `NYTPhotosViewController`.
*/
Expand Down
16 changes: 16 additions & 0 deletions Pod/Classes/ios/NYTPhotosViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ - (void)setLeftBarButtonItem:(UIBarButtonItem *)leftBarButtonItem {
self.overlayView.leftBarButtonItem = leftBarButtonItem;
}

- (NSArray *)leftBarButtonItems {
return self.overlayView.leftBarButtonItems;
}

- (void)setLeftBarButtonItems:(NSArray *)leftBarButtonItems {
self.overlayView.leftBarButtonItems = leftBarButtonItems;
}

- (UIBarButtonItem *)rightBarButtonItem {
return self.overlayView.rightBarButtonItem;
}
Expand All @@ -260,6 +268,14 @@ - (void)setRightBarButtonItem:(UIBarButtonItem *)rightBarButtonItem {
self.overlayView.rightBarButtonItem = rightBarButtonItem;
}

- (NSArray *)rightBarButtonItems {
return self.overlayView.rightBarButtonItems;
}

- (void)setRightBarButtonItems:(NSArray *)rightBarButtonItems {
self.overlayView.rightBarButtonItems = rightBarButtonItems;
}

- (void)displayPhoto:(id <NYTPhoto>)photo animated:(BOOL)animated {
if (![self.dataSource containsPhoto:photo]) {
return;
Expand Down

0 comments on commit 2fd86f5

Please sign in to comment.