Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Support rightBarButtonItems/leftBarButtonItems
Browse files Browse the repository at this point in the history
fix a bug reported in #10 comments
  • Loading branch information
youknowone committed Sep 26, 2013
1 parent 1a61f65 commit 842e269
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
22 changes: 22 additions & 0 deletions UI7Kit/UI7NavigationBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ - (id)__initWithTitle:(NSString *)title { assert(NO); return nil; }
- (void)__setLeftBarButtonItem:(UIBarButtonItem *)leftBarButtonItem animated:(BOOL)animated { assert(NO); }
- (void)__setRightBarButtonItem:(UIBarButtonItem *)rightBarButtonItem animated:(BOOL)animated { assert(NO); }
- (void)__setBackBarButtonItem:(UIBarButtonItem *)backBarButtonItem { assert(NO); }
- (void)__setLeftBarButtonItems:(NSArray *)items animated:(BOOL)animated { assert(NO); }
- (void)__setRightBarButtonItems:(NSArray *)items animated:(BOOL)animated { assert(NO); }

@end

Expand All @@ -261,6 +263,8 @@ + (void)initialize {
[target copyToSelector:@selector(__setLeftBarButtonItem:animated:) fromSelector:@selector(setLeftBarButtonItem:animated:)];
[target copyToSelector:@selector(__setRightBarButtonItem:animated:) fromSelector:@selector(setRightBarButtonItem:animated:)];
[target copyToSelector:@selector(__setBackBarButtonItem:) fromSelector:@selector(setBackBarButtonItem:)];
[target copyToSelector:@selector(__setLeftBarButtonItems:animated:) fromSelector:@selector(setLeftBarButtonItems:animated:)];
[target copyToSelector:@selector(__setRightBarButtonItems:animated:) fromSelector:@selector(setRightBarButtonItems:animated:)];
}
}

Expand All @@ -272,6 +276,8 @@ + (void)patch {
[self exportSelector:@selector(setLeftBarButtonItem:animated:) toClass:target];
[self exportSelector:@selector(setRightBarButtonItem:animated:) toClass:target];
[self exportSelector:@selector(setBackBarButtonItem:) toClass:target];
[self exportSelector:@selector(setLeftBarButtonItems:animated:) toClass:target];
[self exportSelector:@selector(setRightBarButtonItems:animated:) toClass:target];
}

- (id)initWithCoder:(NSCoder *)aDecoder {
Expand Down Expand Up @@ -308,6 +314,22 @@ - (void)setBackBarButtonItem:(UIBarButtonItem *)barButtonItem {
[barButtonItem _tintColorUpdated];
}

- (void)setLeftBarButtonItems:(NSArray *)items animated:(BOOL)animated {
[self __setLeftBarButtonItems:items animated:animated];
for (UIBarButtonItem *barButtonItem in items) {
barButtonItem.appearanceSuperview = self;
[barButtonItem _tintColorUpdated];
}
}

- (void)setRightBarButtonItems:(NSArray *)items animated:(BOOL)animated {
[self __setRightBarButtonItems:items animated:animated];
for (UIBarButtonItem *barButtonItem in items) {
barButtonItem.appearanceSuperview = self;
[barButtonItem _tintColorUpdated];
}
}

//- (UIBarButtonItem *)backBarButtonItem {
// UIBarButtonItem *item = [super backBarButtonItem];
// return item;
Expand Down
20 changes: 10 additions & 10 deletions UI7KitTestApp/Storyboard.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</items>
</navigationBar>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="31D-2p-7gE">
<rect key="frame" x="0.0" y="143" width="320" height="44"/>
<rect key="frame" x="0.0" y="69" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<items>
<barButtonItem systemItem="edit" id="NQu-9R-E6R"/>
Expand All @@ -76,7 +76,7 @@
</items>
</toolbar>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="vgT-tM-B1l">
<rect key="frame" x="0.0" y="187" width="320" height="44"/>
<rect key="frame" x="0.0" y="113" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<items>
<barButtonItem title="Item" systemItem="redo" id="Wcd-Xl-AmS"/>
Expand All @@ -88,7 +88,7 @@
</items>
</toolbar>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="Y46-Xj-hyK">
<rect key="frame" x="0.0" y="231" width="320" height="44"/>
<rect key="frame" x="0.0" y="157" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<items>
<barButtonItem systemItem="trash" id="BKf-5X-PCB"/>
Expand All @@ -100,7 +100,7 @@
</items>
</toolbar>
<toolbar opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="b4B-e6-00p">
<rect key="frame" x="0.0" y="275" width="320" height="44"/>
<rect key="frame" x="0.0" y="201" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<items>
<barButtonItem systemItem="play" id="uJa-2Q-Y56"/>
Expand All @@ -111,7 +111,7 @@
</items>
</toolbar>
<tabBar contentMode="scaleToFill" id="rFU-Do-cP1">
<rect key="frame" x="0.0" y="360" width="320" height="49"/>
<rect key="frame" x="0.0" y="286" width="320" height="49"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<items>
Expand All @@ -124,7 +124,7 @@
</items>
</tabBar>
<tabBar contentMode="scaleToFill" id="bH5-xc-fDV">
<rect key="frame" x="0.0" y="409" width="320" height="49"/>
<rect key="frame" x="0.0" y="335" width="320" height="49"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<items>
Expand Down Expand Up @@ -579,7 +579,7 @@
<navigationItem key="navigationItem" id="HIG-nr-RKe">
<nil key="title"/>
<segmentedControl key="titleView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="bar" selectedSegmentIndex="0" id="kUo-YC-fBn">
<rect key="frame" x="14" y="7" width="292" height="30"/>
<rect key="frame" x="103" y="7" width="115" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<segments>
<segment title="Default"/>
Expand Down Expand Up @@ -678,7 +678,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<searchBar contentMode="redraw" prompt="Prompt" placeholder="placeholder" showsScopeBar="YES" id="w0t-Qv-IQO">
<rect key="frame" x="0.0" y="14" width="320" height="119"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="119"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<textInputTraits key="textInputTraits"/>
<scopeButtonTitles>
Expand Down Expand Up @@ -814,11 +814,11 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" id="dQI-9T-nIQ">
<rect key="frame" x="122" y="143" width="51" height="31"/>
<rect key="frame" x="136" y="134" width="51" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</switch>
<switch opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" id="yk6-DY-Ilx">
<rect key="frame" x="122" y="203" width="51" height="31"/>
<rect key="frame" x="136" y="202" width="51" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</switch>
<view contentMode="scaleToFill" id="nsq-0s-Pun">
Expand Down
6 changes: 4 additions & 2 deletions UI7KitTestApp/UITMasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ - (void)genButton:(id)sender {
systemItem = 0;
}
NSLog(@"genbutton: %d", systemItem);
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem target:self action:@selector(genButton:)];
self.navigationItem.rightBarButtonItem = button;
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem target:self action:@selector(genButton:)];
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem target:self action:@selector(genButton:)];
NSArray *items = arc4random_uniform(2) == 0 ? @[button1] : @[button1, button2];
[self.navigationItem setRightBarButtonItems:items animated:YES];
}

#pragma mark - Table View
Expand Down

0 comments on commit 842e269

Please sign in to comment.