Add example phone number to registration view and make layout responsive.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 070395e8b6
commit 2fc683dd9d

@ -19,6 +19,7 @@
@property (nonatomic) UILabel *countryCodeLabel; @property (nonatomic) UILabel *countryCodeLabel;
@property (nonatomic) UITextField *phoneNumberTextField; @property (nonatomic) UITextField *phoneNumberTextField;
@property (nonatomic) UILabel *examplePhoneNumberLabel;
@property (nonatomic) UIButton *activateButton; @property (nonatomic) UIButton *activateButton;
@property (nonatomic) UIActivityIndicatorView *spinnerView; @property (nonatomic) UIActivityIndicatorView *spinnerView;
@ -57,18 +58,19 @@
UILabel *headerLabel = [UILabel new]; UILabel *headerLabel = [UILabel new];
headerLabel.text = NSLocalizedString(@"REGISTRATION_TITLE_LABEL", @""); headerLabel.text = NSLocalizedString(@"REGISTRATION_TITLE_LABEL", @"");
headerLabel.textColor = [UIColor whiteColor]; headerLabel.textColor = [UIColor whiteColor];
headerLabel.font = [UIFont ows_mediumFontWithSize:20.f]; headerLabel.font = [UIFont ows_mediumFontWithSize:ScaleFromIPhone5To7Plus(20.f, 24.f)];
[header addSubview:headerLabel]; [header addSubview:headerLabel];
[headerLabel autoHCenterInSuperview]; [headerLabel autoHCenterInSuperview];
[headerLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:14.f]; [headerLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:14.f];
CGFloat screenHeight = MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height); CGFloat screenHeight = MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
if (screenHeight < 568) { if (screenHeight < 568) {
// iPhone 4s // iPhone 4s or smaller.
[header autoSetDimension:ALDimensionHeight toSize:20]; [header autoSetDimension:ALDimensionHeight toSize:20];
headerLabel.hidden = YES;
} else if (screenHeight < 667) { } else if (screenHeight < 667) {
// iPhone 5 // iPhone 5 or smaller.
[header autoSetDimension:ALDimensionHeight toSize:120]; [header autoSetDimension:ALDimensionHeight toSize:80];
} else { } else {
[header autoSetDimension:ALDimensionHeight toSize:225]; [header autoSetDimension:ALDimensionHeight toSize:225];
@ -93,6 +95,8 @@
const CGFloat kRowRightMargin = 16.f; const CGFloat kRowRightMargin = 16.f;
const CGFloat kSeparatorHeight = 1.f; const CGFloat kSeparatorHeight = 1.f;
const CGFloat kButtonHMargin = 30.f; const CGFloat kButtonHMargin = 30.f;
const CGFloat kExamplePhoneNumberVSpacing = 8.f;
const CGFloat fontSizePoints = ScaleFromIPhone5To7Plus(16.f, 20.f);
// Country // Country
UIView *countryRow = [UIView new]; UIView *countryRow = [UIView new];
@ -108,7 +112,7 @@
countryNameLabel.text countryNameLabel.text
= NSLocalizedString(@"REGISTRATION_DEFAULT_COUNTRY_NAME", @"Label for the country code field"); = NSLocalizedString(@"REGISTRATION_DEFAULT_COUNTRY_NAME", @"Label for the country code field");
countryNameLabel.textColor = [UIColor blackColor]; countryNameLabel.textColor = [UIColor blackColor];
countryNameLabel.font = [UIFont ows_mediumFontWithSize:16.f]; countryNameLabel.font = [UIFont ows_mediumFontWithSize:fontSizePoints];
[countryRow addSubview:countryNameLabel]; [countryRow addSubview:countryNameLabel];
[countryNameLabel autoVCenterInSuperview]; [countryNameLabel autoVCenterInSuperview];
[countryNameLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kRowLeftMargin]; [countryNameLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kRowLeftMargin];
@ -116,7 +120,7 @@
UILabel *countryCodeLabel = [UILabel new]; UILabel *countryCodeLabel = [UILabel new];
self.countryCodeLabel = countryCodeLabel; self.countryCodeLabel = countryCodeLabel;
countryCodeLabel.textColor = [UIColor ows_materialBlueColor]; countryCodeLabel.textColor = [UIColor ows_materialBlueColor];
countryCodeLabel.font = [UIFont ows_mediumFontWithSize:16.f]; countryCodeLabel.font = [UIFont ows_mediumFontWithSize:fontSizePoints + 2.f];
[countryRow addSubview:countryCodeLabel]; [countryRow addSubview:countryCodeLabel];
[countryCodeLabel autoVCenterInSuperview]; [countryCodeLabel autoVCenterInSuperview];
[countryCodeLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kRowRightMargin]; [countryCodeLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kRowRightMargin];
@ -139,7 +143,7 @@
phoneNumberLabel.text phoneNumberLabel.text
= NSLocalizedString(@"REGISTRATION_PHONENUMBER_BUTTON", @"Label for the phone number textfield"); = NSLocalizedString(@"REGISTRATION_PHONENUMBER_BUTTON", @"Label for the phone number textfield");
phoneNumberLabel.textColor = [UIColor blackColor]; phoneNumberLabel.textColor = [UIColor blackColor];
phoneNumberLabel.font = [UIFont ows_mediumFontWithSize:16.f]; phoneNumberLabel.font = [UIFont ows_mediumFontWithSize:fontSizePoints];
[phoneNumberRow addSubview:phoneNumberLabel]; [phoneNumberRow addSubview:phoneNumberLabel];
[phoneNumberLabel autoVCenterInSuperview]; [phoneNumberLabel autoVCenterInSuperview];
[phoneNumberLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kRowLeftMargin]; [phoneNumberLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kRowLeftMargin];
@ -152,16 +156,30 @@
@"REGISTRATION_ENTERNUMBER_DEFAULT_TEXT", @"Placeholder text for the phone number textfield"); @"REGISTRATION_ENTERNUMBER_DEFAULT_TEXT", @"Placeholder text for the phone number textfield");
self.phoneNumberTextField = phoneNumberTextField; self.phoneNumberTextField = phoneNumberTextField;
phoneNumberTextField.textColor = [UIColor ows_materialBlueColor]; phoneNumberTextField.textColor = [UIColor ows_materialBlueColor];
phoneNumberTextField.font = [UIFont ows_mediumFontWithSize:16.f]; phoneNumberTextField.font = [UIFont ows_mediumFontWithSize:fontSizePoints];
[phoneNumberRow addSubview:phoneNumberTextField]; [phoneNumberRow addSubview:phoneNumberTextField];
[phoneNumberTextField autoVCenterInSuperview]; [phoneNumberTextField autoVCenterInSuperview];
[phoneNumberTextField autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kRowRightMargin]; [phoneNumberTextField autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kRowRightMargin];
UILabel *examplePhoneNumberLabel = [UILabel new];
self.examplePhoneNumberLabel = examplePhoneNumberLabel;
examplePhoneNumberLabel.font = [UIFont ows_regularFontWithSize:fontSizePoints - 2.f];
examplePhoneNumberLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
[contentView addSubview:examplePhoneNumberLabel];
[examplePhoneNumberLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kRowRightMargin];
[examplePhoneNumberLabel autoPinEdge:ALEdgeTop
toEdge:ALEdgeBottom
ofView:phoneNumberTextField
withOffset:kExamplePhoneNumberVSpacing];
UIView *separatorView2 = [UIView new]; UIView *separatorView2 = [UIView new];
separatorView2.backgroundColor = [UIColor colorWithWhite:0.75f alpha:1.f]; separatorView2.backgroundColor = [UIColor colorWithWhite:0.75f alpha:1.f];
[contentView addSubview:separatorView2]; [contentView addSubview:separatorView2];
[separatorView2 autoPinWidthToSuperview]; [separatorView2 autoPinWidthToSuperview];
[separatorView2 autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:phoneNumberRow]; [separatorView2 autoPinEdge:ALEdgeTop
toEdge:ALEdgeBottom
ofView:phoneNumberRow
withOffset:examplePhoneNumberLabel.font.lineHeight];
[separatorView2 autoSetDimension:ALDimensionHeight toSize:kSeparatorHeight]; [separatorView2 autoSetDimension:ALDimensionHeight toSize:kSeparatorHeight];
// Activate Button // Activate Button
@ -170,13 +188,16 @@
activateButton.backgroundColor = [UIColor ows_signalBrandBlueColor]; activateButton.backgroundColor = [UIColor ows_signalBrandBlueColor];
[activateButton setTitle:NSLocalizedString(@"REGISTRATION_VERIFY_DEVICE", @"") forState:UIControlStateNormal]; [activateButton setTitle:NSLocalizedString(@"REGISTRATION_VERIFY_DEVICE", @"") forState:UIControlStateNormal];
[activateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [activateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
activateButton.titleLabel.font = [UIFont ows_mediumFontWithSize:16.f]; activateButton.titleLabel.font = [UIFont ows_boldFontWithSize:fontSizePoints];
[activateButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter]; [activateButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[activateButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter]; [activateButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[contentView addSubview:activateButton]; [contentView addSubview:activateButton];
[activateButton autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kButtonHMargin]; [activateButton autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:kButtonHMargin];
[activateButton autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kButtonHMargin]; [activateButton autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:kButtonHMargin];
[activateButton autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:separatorView2 withOffset:9.f]; [activateButton autoPinEdge:ALEdgeTop
toEdge:ALEdgeBottom
ofView:separatorView2
withOffset:ScaleFromIPhone5To7Plus(12.f, 15.f)];
[activateButton autoSetDimension:ALDimensionHeight toSize:47.f]; [activateButton autoSetDimension:ALDimensionHeight toSize:47.f];
[activateButton addTarget:self action:@selector(sendCodeAction:) forControlEvents:UIControlEventTouchUpInside]; [activateButton addTarget:self action:@selector(sendCodeAction:) forControlEvents:UIControlEventTouchUpInside];
@ -195,7 +216,7 @@
[existingAccountButton setTitle:NSLocalizedString(@"ALREADY_HAVE_ACCOUNT_BUTTON", @"registration button text") [existingAccountButton setTitle:NSLocalizedString(@"ALREADY_HAVE_ACCOUNT_BUTTON", @"registration button text")
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[existingAccountButton setTitleColor:[UIColor ows_materialBlueColor] forState:UIControlStateNormal]; [existingAccountButton setTitleColor:[UIColor ows_materialBlueColor] forState:UIControlStateNormal];
existingAccountButton.titleLabel.font = [UIFont ows_mediumFontWithSize:16.f]; existingAccountButton.titleLabel.font = [UIFont ows_mediumFontWithSize:fontSizePoints - 2.f];
[existingAccountButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter]; [existingAccountButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[existingAccountButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter]; [existingAccountButton setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
[contentView addSubview:existingAccountButton]; [contentView addSubview:existingAccountButton];
@ -241,6 +262,10 @@
countryCode.uppercaseString]; countryCode.uppercaseString];
self.countryCodeLabel.text = title; self.countryCodeLabel.text = title;
[self.countryCodeLabel setNeedsLayout]; [self.countryCodeLabel setNeedsLayout];
self.examplePhoneNumberLabel.text =
[ViewControllerUtils examplePhoneNumberForCountryCode:countryCode callingCode:callingCode];
[self.examplePhoneNumberLabel setNeedsLayout];
} }
#pragma mark - Actions #pragma mark - Actions

@ -252,24 +252,8 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien
[self.countryCodeButton setTitle:title forState:UIControlStateNormal]; [self.countryCodeButton setTitle:title forState:UIControlStateNormal];
[self.countryCodeButton layoutSubviews]; [self.countryCodeButton layoutSubviews];
NSString *examplePhoneNumber = [PhoneNumberUtil examplePhoneNumberForCountryCode:countryCode]; self.examplePhoneNumberLabel.text =
OWSAssert(!examplePhoneNumber || [examplePhoneNumber hasPrefix:callingCode]); [ViewControllerUtils examplePhoneNumberForCountryCode:countryCode callingCode:callingCode];
if (examplePhoneNumber && [examplePhoneNumber hasPrefix:callingCode]) {
NSString *formattedPhoneNumber =
[PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:examplePhoneNumber
withSpecifiedCountryCodeString:countryCode];
if (formattedPhoneNumber.length > 0) {
examplePhoneNumber = formattedPhoneNumber;
}
self.examplePhoneNumberLabel.text = [NSString
stringWithFormat:
NSLocalizedString(@"PHONE_NUMBER_EXAMPLE_FORMAT",
@"A format for a label showing an example phone number. Embeds {{the example phone number}}."),
[examplePhoneNumber substringFromIndex:callingCode.length]];
} else {
self.examplePhoneNumberLabel.text = @"";
}
[self.examplePhoneNumberLabel.superview layoutSubviews]; [self.examplePhoneNumberLabel.superview layoutSubviews];
} }

@ -4,6 +4,8 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface ViewControllerUtils : NSObject @interface ViewControllerUtils : NSObject
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
@ -22,4 +24,8 @@
+ (NSString *)formatDurationSeconds:(long)timeSeconds; + (NSString *)formatDurationSeconds:(long)timeSeconds;
+ (NSString *)examplePhoneNumberForCountryCode:(NSString *)countryCode callingCode:(NSString *)callingCode;
@end @end
NS_ASSUME_NONNULL_END

@ -115,6 +115,31 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
+ (NSString *)examplePhoneNumberForCountryCode:(NSString *)countryCode callingCode:(NSString *)callingCode
{
OWSAssert(countryCode.length > 0);
OWSAssert(callingCode.length > 0);
NSString *examplePhoneNumber = [PhoneNumberUtil examplePhoneNumberForCountryCode:countryCode];
OWSAssert(!examplePhoneNumber || [examplePhoneNumber hasPrefix:callingCode]);
if (examplePhoneNumber && [examplePhoneNumber hasPrefix:callingCode]) {
NSString *formattedPhoneNumber =
[PhoneNumber bestEffortFormatPartialUserSpecifiedTextToLookLikeAPhoneNumber:examplePhoneNumber
withSpecifiedCountryCodeString:countryCode];
if (formattedPhoneNumber.length > 0) {
examplePhoneNumber = formattedPhoneNumber;
}
return [NSString
stringWithFormat:
NSLocalizedString(@"PHONE_NUMBER_EXAMPLE_FORMAT",
@"A format for a label showing an example phone number. Embeds {{the example phone number}}."),
[examplePhoneNumber substringFromIndex:callingCode.length]];
} else {
return @"";
}
}
#pragma mark - Logging #pragma mark - Logging
+ (NSString *)tag + (NSString *)tag

Loading…
Cancel
Save