Skip to content

Commit

Permalink
feat(Contacts): use UITabBarItems on tab view controller
Browse files Browse the repository at this point in the history
  • Loading branch information
kwgithubusername committed Jul 27, 2017
1 parent d657195 commit 3290cf1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 107 deletions.
83 changes: 22 additions & 61 deletions Blockchain/Base.lproj/MainWindow.xib
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12120" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
Expand Down Expand Up @@ -552,74 +552,35 @@
</subviews>
<color key="backgroundColor" red="0.023529411760000001" green="0.21960784310000001" blue="0.41176470590000003" alpha="1" colorSpace="calibratedRGB"/>
</view>
<view opaque="NO" contentMode="scaleToFill" misplaced="YES" id="284" userLabel="Tab Bar">
<tabBar contentMode="scaleToFill" misplaced="YES" id="qFz-ib-jRL">
<rect key="frame" x="0.0" y="431" width="320" height="49"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="172" userLabel="Button Send">
<rect key="frame" x="0.0" y="3" width="106" height="46"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="10"/>
<state key="normal" image="send">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<state key="highlighted" image="send_blue">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="sendCoinsClicked:" destination="3" eventType="touchUpInside" id="ah2-zk-413"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="173" userLabel="Button Transactions">
<rect key="frame" x="106" y="3" width="106" height="46"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="10"/>
<state key="normal" image="tx">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<state key="highlighted" image="tx_blue">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="transactionsClicked:" destination="3" eventType="touchUpInside" id="ivM-8b-yTe"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="174" userLabel="Button Receive">
<rect key="frame" x="212" y="3" width="106" height="46"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
<fontDescription key="fontDescription" name="Helvetica" family="Helvetica" pointSize="10"/>
<state key="normal" image="receive">
<color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<state key="highlighted" image="receive_blue">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="receiveCoinClicked:" destination="3" eventType="touchUpInside" id="Qg5-Ol-Fo8"/>
</connections>
</button>
<view contentMode="scaleToFill" id="5Vm-Gr-tyR" userLabel="Separator" customClass="BCLine">
<rect key="frame" x="0.0" y="0.0" width="320" height="1"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" red="0.66666666666666663" green="0.66666666666666663" blue="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<items>
<tabBarItem title="Send" image="send" selectedImage="send_blue" id="GXY-NY-C2f">
<offsetWrapper key="titlePositionAdjustment" horizontal="0.0" vertical="-3"/>
</tabBarItem>
<tabBarItem title="Overview" image="tx" selectedImage="tx_blue" id="mk4-R4-oj0">
<offsetWrapper key="titlePositionAdjustment" horizontal="0.0" vertical="-3"/>
</tabBarItem>
<tabBarItem title="Item" image="receive" selectedImage="receive_blue" id="vd6-98-LQG">
<offsetWrapper key="titlePositionAdjustment" horizontal="0.0" vertical="-3"/>
</tabBarItem>
</items>
<color key="tintColor" red="0.094117647060000004" green="0.61176470589999998" blue="0.86666666670000003" alpha="1" colorSpace="calibratedRGB"/>
<color key="selectedImageTintColor" red="0.094117647060000004" green="0.61176470589999998" blue="0.86666666670000003" alpha="1" colorSpace="calibratedRGB"/>
</tabBar>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<size key="freeformSize" width="320" height="480"/>
<connections>
<outlet property="contentView" destination="290" id="291"/>
<outlet property="homeButton" destination="173" id="SKk-KS-6WH"/>
<outlet property="receiveButton" destination="174" id="ykJ-CJ-2W1"/>
<outlet property="sendButton" destination="172" id="1WE-Bw-2cJ"/>
<outlet property="tabBar" destination="284" id="frm-US-5wu"/>
<outlet property="homeButton" destination="mk4-R4-oj0" id="Hdv-6Q-LhG"/>
<outlet property="receiveButton" destination="vd6-98-LQG" id="Llf-CK-yVb"/>
<outlet property="sendButton" destination="GXY-NY-C2f" id="YeQ-nQ-WY3"/>
<outlet property="tabBar" destination="qFz-ib-jRL" id="hHK-6C-bef"/>
</connections>
<point key="canvasLocation" x="-244" y="-310"/>
</viewController>
Expand Down
6 changes: 3 additions & 3 deletions Blockchain/RootService.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@
- (void)showHdUpgrade;
- (void)showBackupReminder:(BOOL)firstReceive;

- (IBAction)receiveCoinClicked:(UIButton *)sender;
- (IBAction)transactionsClicked:(UIButton *)sender;
- (IBAction)sendCoinsClicked:(UIButton *)sender;
- (void)receiveCoinClicked:(UITabBarItem *)sender;
- (void)transactionsClicked:(UITabBarItem *)sender;
- (void)sendCoinsClicked:(UITabBarItem *)sender;
- (IBAction)merchantClicked:(UIButton *)sender;
- (IBAction)QRCodebuttonClicked:(id)sender;
- (IBAction)forgetWalletClicked:(id)sender;
Expand Down
6 changes: 3 additions & 3 deletions Blockchain/RootService.m
Original file line number Diff line number Diff line change
Expand Up @@ -2917,7 +2917,7 @@ - (void)presentViewControllerAnimated:(UIViewController *)viewController
[app.window.rootViewController presentViewController:viewController animated:YES completion:nil];
}

- (IBAction)receiveCoinClicked:(UIButton *)sender
- (void)receiveCoinClicked:(UITabBarItem *)sender
{
if (!_receiveViewController) {
_receiveViewController = [[ReceiveCoinsViewController alloc] initWithNibName:NIB_NAME_RECEIVE_COINS bundle:[NSBundle mainBundle]];
Expand All @@ -2926,7 +2926,7 @@ - (IBAction)receiveCoinClicked:(UIButton *)sender
[_tabViewController setActiveViewController:_receiveViewController animated:TRUE index:2];
}

- (IBAction)transactionsClicked:(UIButton *)sender
- (void)transactionsClicked:(UITabBarItem *)sender
{
[_tabViewController setActiveViewController:_transactionsViewController animated:TRUE index:1];

Expand All @@ -2944,7 +2944,7 @@ - (IBAction)transactionsClicked:(UIButton *)sender
}
}

- (IBAction)sendCoinsClicked:(UIButton *)sender
- (void)sendCoinsClicked:(UITabBarItem *)sender
{
[self showSendCoins];
}
Expand Down
10 changes: 5 additions & 5 deletions Blockchain/TabViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// Copyright 2010 __MyCompanyName__. All rights reserved.
//

@interface TabViewcontroller : UIViewController {
IBOutlet UIButton *sendButton;
IBOutlet UIButton *homeButton;
IBOutlet UIButton *receiveButton;
IBOutlet UIView *tabBar;
@interface TabViewcontroller : UIViewController <UITabBarDelegate> {
IBOutlet UITabBarItem *sendButton;
IBOutlet UITabBarItem *homeButton;
IBOutlet UITabBarItem *receiveButton;
IBOutlet UITabBar *tabBar;

UIViewController *activeViewController;
UIViewController *oldViewController;
Expand Down
58 changes: 23 additions & 35 deletions Blockchain/TabViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ @implementation TabViewcontroller
- (void)awakeFromNib
{
[super awakeFromNib];

tabBar.delegate = self;

// Default selected: transactions
selectedIndex = TAB_TRANSACTIONS;

Expand All @@ -39,25 +42,15 @@ - (void)viewDidAppear:(BOOL)animated

- (void)setupTabButtons
{
CGFloat spacing = 2.0;

NSDictionary *tabButtons = @{BC_STRING_SEND:sendButton, BC_STRING_OVERVIEW:homeButton, BC_STRING_REQUEST:receiveButton};

for (UIButton *button in [tabButtons allValues]) {

for (UITabBarItem *button in [tabButtons allValues]) {
NSString *label = [[tabButtons allKeysForObject:button] firstObject];
[button setTitle:label forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont fontWithName:FONT_MONTSERRAT_REGULAR size:FONT_SIZE_EXTRA_EXTRA_EXTRA_SMALL]];
CGSize titleSize = [label sizeWithAttributes:@{NSFontAttributeName: button.titleLabel.font}];

CGSize imageSize = button.imageView.image.size;
button.imageEdgeInsets = UIEdgeInsetsMake(-(titleSize.height + spacing), 0, 0, -titleSize.width);

button.titleEdgeInsets = UIEdgeInsetsMake(0, -imageSize.width, -(imageSize.height + spacing), 0);
[button setTitleColor:COLOR_TEXT_DARK_GRAY forState:UIControlStateNormal];
[button setTitleColor:COLOR_BLOCKCHAIN_LIGHT_BLUE forState:UIControlStateHighlighted];

button.titleLabel.adjustsFontSizeToFitWidth = YES;
button.title = label;
button.image = [button.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
button.selectedImage = [button.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[button setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:FONT_MONTSERRAT_REGULAR size:FONT_SIZE_EXTRA_EXTRA_EXTRA_SMALL], NSForegroundColorAttributeName : COLOR_TEXT_DARK_GRAY} forState:UIControlStateNormal];
[button setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:FONT_MONTSERRAT_REGULAR size:FONT_SIZE_EXTRA_EXTRA_EXTRA_SMALL], NSForegroundColorAttributeName : COLOR_BLOCKCHAIN_LIGHT_BLUE} forState:UIControlStateHighlighted];
}
}

Expand Down Expand Up @@ -119,26 +112,10 @@ - (void)setSelectedIndex:(int)nindex
{
selectedIndex = nindex;

sendButton.highlighted = NO;
homeButton.highlighted = NO;
receiveButton.highlighted = NO;
sendButton.userInteractionEnabled = YES;
homeButton.userInteractionEnabled = YES;
receiveButton.userInteractionEnabled = YES;

tabBar.selectedItem = nil;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (selectedIndex == TAB_SEND) {
sendButton.highlighted = YES;
sendButton.userInteractionEnabled = NO;
}
else if (selectedIndex == TAB_TRANSACTIONS) {
homeButton.highlighted = YES;
homeButton.userInteractionEnabled = NO;
}
else if (selectedIndex == TAB_RECEIVE) {
receiveButton.highlighted = YES;
receiveButton.userInteractionEnabled = NO;
}
tabBar.selectedItem = [[tabBar items] objectAtIndex:selectedIndex];
});
}

Expand All @@ -159,4 +136,15 @@ - (void)removeTapGestureRecognizerFromTabBar:(UITapGestureRecognizer *)tapGestur
self.tabBarGestureView = nil;
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if (item == sendButton) {
[app sendCoinsClicked:item];
} else if (item == homeButton) {
[app transactionsClicked:item];
} else if (item == receiveButton) {
[app receiveCoinClicked:item];
}
}

@end

0 comments on commit 3290cf1

Please sign in to comment.