From 46d00383fd014b2397779353b2211ea5b5925fdd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 12 Sep 2017 10:40:23 -0400 Subject: [PATCH] Create Flat UI rounded button class. // FREEBIE --- .../CodeVerificationViewController.m | 2 ++ .../ViewControllers/ProfileViewController.m | 29 ++++++++-------- .../RegistrationViewController.m | 2 ++ .../SelectRecipientViewController.m | 33 ++++++++----------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/Signal/src/ViewControllers/CodeVerificationViewController.m b/Signal/src/ViewControllers/CodeVerificationViewController.m index 4773697dd..b54a525c0 100644 --- a/Signal/src/ViewControllers/CodeVerificationViewController.m +++ b/Signal/src/ViewControllers/CodeVerificationViewController.m @@ -156,6 +156,8 @@ NS_ASSUME_NONNULL_BEGIN [underscoreView autoSetDimension:ALDimensionHeight toSize:1.f]; const CGFloat kSubmitButtonHeight = 47.f; + // NOTE: We use ows_signalBrandBlueColor instead of ows_materialBlueColor + // throughout the onboarding flow to be consistent with the headers. OWSFlatButton *submitButton = [OWSFlatButton buttonWithTitle:NSLocalizedString(@"VERIFICATION_CHALLENGE_SUBMIT_CODE", @"button text during registration to submit your SMS verification code.") diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 185c8d2ca..53f605e75 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -38,7 +38,7 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat @property (nonatomic) UIImageView *cameraImageView; -@property (nonatomic) UIButton *saveButton; +@property (nonatomic) OWSFlatButton *saveButton; @property (nonatomic, nullable) UIImage *avatar; @@ -209,21 +209,22 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat UIView *buttonRow = [UIView containerView]; [rows addObject:buttonRow]; - UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeCustom]; + const CGFloat kButtonHeight = 47.f; + // NOTE: We use ows_signalBrandBlueColor instead of ows_materialBlueColor + // throughout the onboarding flow to be consistent with the headers. + OWSFlatButton *saveButton = + [OWSFlatButton buttonWithTitle:NSLocalizedString(@"PROFILE_VIEW_SAVE_BUTTON", + @"Button to save the profile view in the profile view.") + font:[OWSFlatButton fontForHeight:kButtonHeight] + titleColor:[UIColor whiteColor] + backgroundColor:[UIColor ows_signalBrandBlueColor] + target:self + selector:@selector(saveButtonPressed)]; self.saveButton = saveButton; - saveButton.backgroundColor = [UIColor ows_signalBrandBlueColor]; - [saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; - saveButton.titleLabel.font = [UIFont ows_boldFontWithSize:fontSizePoints]; - [saveButton setTitle:NSLocalizedString( - @"PROFILE_VIEW_SAVE_BUTTON", @"Button to save the profile view in the profile view.") - forState:UIControlStateNormal]; - [saveButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter]; - [saveButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter]; [buttonRow addSubview:saveButton]; [saveButton autoPinLeadingAndTrailingToSuperview]; [saveButton autoPinHeightToSuperview]; [saveButton autoSetDimension:ALDimensionHeight toSize:47.f]; - [saveButton addTarget:self action:@selector(saveButtonPressed) forControlEvents:UIControlEventTouchUpInside]; } // Row Layout @@ -345,11 +346,11 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat // The save button is only used in "registration" and "upgrade or nag" modes. if (self.hasUnsavedChanges) { self.saveButton.enabled = YES; - self.saveButton.backgroundColor = [UIColor ows_signalBrandBlueColor]; + [self.saveButton setBackgroundColors:[UIColor ows_signalBrandBlueColor]]; } else { self.saveButton.enabled = NO; - self.saveButton.backgroundColor = - [[UIColor ows_signalBrandBlueColor] blendWithColor:[UIColor whiteColor] alpha:0.5f]; + [self.saveButton + setBackgroundColors:[[UIColor ows_signalBrandBlueColor] blendWithColor:[UIColor whiteColor] alpha:0.5f]]; } } diff --git a/Signal/src/ViewControllers/RegistrationViewController.m b/Signal/src/ViewControllers/RegistrationViewController.m index f47cfa638..bd556ba66 100644 --- a/Signal/src/ViewControllers/RegistrationViewController.m +++ b/Signal/src/ViewControllers/RegistrationViewController.m @@ -199,6 +199,8 @@ NSString *const kKeychainKey_LastRegisteredPhoneNumber = @"kKeychainKey_LastRegi // Activate Button const CGFloat kActivateButtonHeight = 47.f; + // NOTE: We use ows_signalBrandBlueColor instead of ows_materialBlueColor + // throughout the onboarding flow to be consistent with the headers. OWSFlatButton *activateButton = [OWSFlatButton buttonWithTitle:NSLocalizedString(@"REGISTRATION_VERIFY_DEVICE", @"") font:[OWSFlatButton fontForHeight:kActivateButtonHeight] titleColor:[UIColor whiteColor] diff --git a/Signal/src/ViewControllers/SelectRecipientViewController.m b/Signal/src/ViewControllers/SelectRecipientViewController.m index 379d1110a..acf5e33d5 100644 --- a/Signal/src/ViewControllers/SelectRecipientViewController.m +++ b/Signal/src/ViewControllers/SelectRecipientViewController.m @@ -37,7 +37,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien @property (nonatomic) UITextField *phoneNumberTextField; -@property (nonatomic) UIButton *phoneNumberButton; +@property (nonatomic) OWSFlatButton *phoneNumberButton; @property (nonatomic) UILabel *examplePhoneNumberLabel; @@ -172,24 +172,19 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien return _phoneNumberTextField; } -- (UIButton *)phoneNumberButton +- (OWSFlatButton *)phoneNumberButton { if (!_phoneNumberButton) { - // TODO: Eventually we should make a view factory that will allow us to - // create views with consistent appearance across the app and move - // towards a "design language." - _phoneNumberButton = [UIButton buttonWithType:UIButtonTypeCustom]; - _phoneNumberButton.titleLabel.font = [UIFont ows_mediumFontWithSize:18.f]; - [_phoneNumberButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; - [_phoneNumberButton setBackgroundColor:[UIColor ows_materialBlueColor]]; - _phoneNumberButton.clipsToBounds = YES; - _phoneNumberButton.layer.cornerRadius = 3.f; - [_phoneNumberButton setTitle:[self.delegate phoneNumberButtonText] forState:UIControlStateNormal]; - [_phoneNumberButton addTarget:self - action:@selector(phoneNumberButtonPressed:) - forControlEvents:UIControlEventTouchUpInside]; - [_phoneNumberButton autoSetDimension:ALDimensionWidth toSize:140]; - [_phoneNumberButton autoSetDimension:ALDimensionHeight toSize:40]; + const CGFloat kButtonHeight = 40; + OWSFlatButton *button = [OWSFlatButton buttonWithTitle:[self.delegate phoneNumberButtonText] + font:[OWSFlatButton fontForHeight:kButtonHeight] + titleColor:[UIColor whiteColor] + backgroundColor:[UIColor ows_materialBlueColor] + target:self + selector:@selector(phoneNumberButtonPressed)]; + _phoneNumberButton = button; + [button autoSetDimension:ALDimensionWidth toSize:140]; + [button autoSetDimension:ALDimensionHeight toSize:kButtonHeight]; } return _phoneNumberButton; } @@ -275,7 +270,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien [self presentViewController:navigationController animated:YES completion:[UIUtil modalCompletionBlock]]; } -- (void)phoneNumberButtonPressed:(id)sender +- (void)phoneNumberButtonPressed { [self tryToSelectPhoneNumber]; } @@ -387,7 +382,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien BOOL isEnabled = [self hasValidPhoneNumber]; self.phoneNumberButton.enabled = isEnabled; [self.phoneNumberButton - setBackgroundColor:(isEnabled ? [UIColor ows_signalBrandBlueColor] : [UIColor lightGrayColor])]; + setBackgroundColors:(isEnabled ? [UIColor ows_signalBrandBlueColor] : [UIColor lightGrayColor])]; } #pragma mark - CountryCodeViewControllerDelegate