Commit f9d0a2bb authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] make manual fallback buttons larger and with touch highlight

Bug: 907082,907001
Change-Id: I30d4a9f0a1463f3b500cefc255b4335bde790b37
Reviewed-on: https://chromium-review.googlesource.com/c/1348109Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610637}
parent 652678d2
...@@ -88,6 +88,8 @@ source_set("manual_fill_ui") { ...@@ -88,6 +88,8 @@ source_set("manual_fill_ui") {
"manual_fill_address_cell.mm", "manual_fill_address_cell.mm",
"manual_fill_card_cell.h", "manual_fill_card_cell.h",
"manual_fill_card_cell.mm", "manual_fill_card_cell.mm",
"manual_fill_cell_button.h",
"manual_fill_cell_button.mm",
"manual_fill_cell_utils.h", "manual_fill_cell_utils.h",
"manual_fill_cell_utils.mm", "manual_fill_cell_utils.mm",
"manual_fill_content_delegate.h", "manual_fill_content_delegate.h",
......
...@@ -48,18 +48,12 @@ ...@@ -48,18 +48,12 @@
namespace { namespace {
// Left and right margins of the cell content. // Left and right margins of the cell content.
static const CGFloat sideMargins = 16; static const CGFloat SideMargins = 16;
// Margin left and right of multiple buttons on same line.
static const CGFloat InnerMarginWidth = 16.0;
} // namespace } // namespace
@interface ManualFillAddressCell () @interface ManualFillAddressCell ()
// The separator gray line.
@property(nonatomic, strong) UIView* grayLine;
// The label with the line1 -- line2. // The label with the line1 -- line2.
@property(nonatomic, strong) UILabel* addressLabel; @property(nonatomic, strong) UILabel* addressLabel;
...@@ -158,6 +152,7 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -158,6 +152,7 @@ static const CGFloat InnerMarginWidth = 16.0;
self.delegate = delegate; self.delegate = delegate;
NSMutableArray<UIView*>* verticalLeadViews = [[NSMutableArray alloc] init]; NSMutableArray<UIView*>* verticalLeadViews = [[NSMutableArray alloc] init];
UIView* guide = self.contentView;
// Top label, summary of line 1 and 2. // Top label, summary of line 1 and 2.
NSMutableAttributedString* attributedString = NSMutableAttributedString* attributedString =
...@@ -232,8 +227,8 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -232,8 +227,8 @@ static const CGFloat InnerMarginWidth = 16.0;
self.lastNameButton.hidden = YES; self.lastNameButton.hidden = YES;
} }
self.nameLineConstraints = HorizontalConstraintsForViewsOnGuideWithShift( self.nameLineConstraints =
nameLineViews, self.grayLine, -InnerMarginWidth); HorizontalConstraintsForViewsOnGuideWithShift(nameLineViews, guide, 0);
if (nameLineViews.count) { if (nameLineViews.count) {
[verticalLeadViews addObject:nameLineViews.firstObject]; [verticalLeadViews addObject:nameLineViews.firstObject];
...@@ -283,8 +278,8 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -283,8 +278,8 @@ static const CGFloat InnerMarginWidth = 16.0;
self.cityButton.hidden = YES; self.cityButton.hidden = YES;
} }
self.zipCityLineConstraints = HorizontalConstraintsForViewsOnGuideWithShift( self.zipCityLineConstraints =
zipCityLineViews, self.grayLine, -InnerMarginWidth); HorizontalConstraintsForViewsOnGuideWithShift(zipCityLineViews, guide, 0);
if (zipCityLineViews.count) { if (zipCityLineViews.count) {
[verticalLeadViews addObject:zipCityLineViews.firstObject]; [verticalLeadViews addObject:zipCityLineViews.firstObject];
} }
...@@ -317,8 +312,8 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -317,8 +312,8 @@ static const CGFloat InnerMarginWidth = 16.0;
} }
self.stateCountryLineConstraints = self.stateCountryLineConstraints =
HorizontalConstraintsForViewsOnGuideWithShift( HorizontalConstraintsForViewsOnGuideWithShift(stateCountryLineViews,
stateCountryLineViews, self.grayLine, -InnerMarginWidth); guide, 0);
if (stateCountryLineViews.count) { if (stateCountryLineViews.count) {
[verticalLeadViews addObject:stateCountryLineViews.firstObject]; [verticalLeadViews addObject:stateCountryLineViews.firstObject];
} }
...@@ -333,21 +328,21 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -333,21 +328,21 @@ static const CGFloat InnerMarginWidth = 16.0;
- (void)createViewHierarchy { - (void)createViewHierarchy {
self.selectionStyle = UITableViewCellSelectionStyleNone; self.selectionStyle = UITableViewCellSelectionStyleNone;
self.grayLine = [[UIView alloc] init]; UIView* grayLine = [[UIView alloc] init];
self.grayLine.backgroundColor = [UIColor colorWithWhite:0.88 alpha:1]; grayLine.backgroundColor = [UIColor colorWithWhite:0.88 alpha:1];
self.grayLine.translatesAutoresizingMaskIntoConstraints = NO; grayLine.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:self.grayLine]; [self.contentView addSubview:grayLine];
UIView* guide = self.contentView;
self.addressLabel = CreateLabel(); self.addressLabel = CreateLabel();
[self.contentView addSubview:self.addressLabel]; [self.contentView addSubview:self.addressLabel];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.addressLabel ], HorizontalConstraintsForViewsOnGuideWithShift(@[ self.addressLabel ], guide,
self.grayLine, 0); SideMargins);
self.firstNameButton = CreateButtonWithSelectorAndTarget( self.firstNameButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self); @selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.firstNameButton]; [self.contentView addSubview:self.firstNameButton];
HorizontalConstraintsMarginForButtonWithWidth(self.firstNameButton,
InnerMarginWidth);
self.middleNameSeparatorLabel = CreateLabel(); self.middleNameSeparatorLabel = CreateLabel();
self.middleNameSeparatorLabel.text = @"·"; self.middleNameSeparatorLabel.text = @"·";
...@@ -356,8 +351,6 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -356,8 +351,6 @@ static const CGFloat InnerMarginWidth = 16.0;
self.middleNameButton = CreateButtonWithSelectorAndTarget( self.middleNameButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self); @selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.middleNameButton]; [self.contentView addSubview:self.middleNameButton];
HorizontalConstraintsMarginForButtonWithWidth(self.middleNameButton,
InnerMarginWidth);
self.lastNameSeparatorLabel = CreateLabel(); self.lastNameSeparatorLabel = CreateLabel();
self.lastNameSeparatorLabel.text = @"·"; self.lastNameSeparatorLabel.text = @"·";
...@@ -366,8 +359,6 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -366,8 +359,6 @@ static const CGFloat InnerMarginWidth = 16.0;
self.lastNameButton = CreateButtonWithSelectorAndTarget( self.lastNameButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self); @selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.lastNameButton]; [self.contentView addSubview:self.lastNameButton];
HorizontalConstraintsMarginForButtonWithWidth(self.lastNameButton,
InnerMarginWidth);
SyncBaselinesForViewsOnView( SyncBaselinesForViewsOnView(
@[ @[
...@@ -379,20 +370,18 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -379,20 +370,18 @@ static const CGFloat InnerMarginWidth = 16.0;
self.line1Button = CreateButtonWithSelectorAndTarget( self.line1Button = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self); @selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.line1Button]; [self.contentView addSubview:self.line1Button];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.line1Button ], HorizontalConstraintsForViewsOnGuideWithShift(@[ self.line1Button ], guide,
self.grayLine, 0); 0);
self.line2Button = CreateButtonWithSelectorAndTarget( self.line2Button = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self); @selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.line2Button]; [self.contentView addSubview:self.line2Button];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.line2Button ], HorizontalConstraintsForViewsOnGuideWithShift(@[ self.line2Button ], guide,
self.grayLine, 0); 0);
self.zipButton = CreateButtonWithSelectorAndTarget( self.zipButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self); @selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.zipButton]; [self.contentView addSubview:self.zipButton];
HorizontalConstraintsMarginForButtonWithWidth(self.zipButton,
InnerMarginWidth);
self.citySeparatorLabel = CreateLabel(); self.citySeparatorLabel = CreateLabel();
self.citySeparatorLabel.text = @"·"; self.citySeparatorLabel.text = @"·";
...@@ -401,8 +390,6 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -401,8 +390,6 @@ static const CGFloat InnerMarginWidth = 16.0;
self.cityButton = CreateButtonWithSelectorAndTarget( self.cityButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self); @selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.cityButton]; [self.contentView addSubview:self.cityButton];
HorizontalConstraintsMarginForButtonWithWidth(self.cityButton,
InnerMarginWidth);
SyncBaselinesForViewsOnView(@[ self.citySeparatorLabel, self.cityButton ], SyncBaselinesForViewsOnView(@[ self.citySeparatorLabel, self.cityButton ],
self.zipButton); self.zipButton);
...@@ -410,8 +397,6 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -410,8 +397,6 @@ static const CGFloat InnerMarginWidth = 16.0;
self.stateButton = CreateButtonWithSelectorAndTarget( self.stateButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self); @selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.stateButton]; [self.contentView addSubview:self.stateButton];
HorizontalConstraintsMarginForButtonWithWidth(self.stateButton,
InnerMarginWidth);
self.countrySeparatorLabel = CreateLabel(); self.countrySeparatorLabel = CreateLabel();
self.countrySeparatorLabel.text = @"·"; self.countrySeparatorLabel.text = @"·";
...@@ -420,8 +405,6 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -420,8 +405,6 @@ static const CGFloat InnerMarginWidth = 16.0;
self.countryButton = CreateButtonWithSelectorAndTarget( self.countryButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapAddressInfo:), self); @selector(userDidTapAddressInfo:), self);
[self.contentView addSubview:self.countryButton]; [self.contentView addSubview:self.countryButton];
HorizontalConstraintsMarginForButtonWithWidth(self.countryButton,
InnerMarginWidth);
SyncBaselinesForViewsOnView( SyncBaselinesForViewsOnView(
@[ self.countrySeparatorLabel, self.countryButton ], self.stateButton); @[ self.countrySeparatorLabel, self.countryButton ], self.stateButton);
...@@ -435,16 +418,15 @@ static const CGFloat InnerMarginWidth = 16.0; ...@@ -435,16 +418,15 @@ static const CGFloat InnerMarginWidth = 16.0;
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
// Common vertical constraints. // Common vertical constraints.
[self.grayLine.bottomAnchor [grayLine.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor], constraintEqualToAnchor:self.contentView.bottomAnchor],
[self.grayLine.heightAnchor constraintEqualToConstant:1], [grayLine.heightAnchor constraintEqualToConstant:1],
// Horizontal constraints. // Horizontal constraints.
[self.grayLine.leadingAnchor constraintEqualToAnchor:safeArea.leadingAnchor [grayLine.leadingAnchor constraintEqualToAnchor:safeArea.leadingAnchor
constant:sideMargins], constant:SideMargins],
[safeArea.trailingAnchor [safeArea.trailingAnchor constraintEqualToAnchor:grayLine.trailingAnchor
constraintEqualToAnchor:self.grayLine.trailingAnchor constant:SideMargins],
constant:sideMargins],
]]; ]];
} }
......
...@@ -66,10 +66,7 @@ ...@@ -66,10 +66,7 @@
namespace { namespace {
// Left and right margins of the cell content. // Left and right margins of the cell content.
static const CGFloat sideMargins = 16; static const CGFloat SideMargins = 16;
// Margin left and right of expiration buttons.
static const CGFloat ExpirationMarginWidth = 16.0;
} // namespace } // namespace
...@@ -167,33 +164,31 @@ static const CGFloat ExpirationMarginWidth = 16.0; ...@@ -167,33 +164,31 @@ static const CGFloat ExpirationMarginWidth = 16.0;
grayLine.translatesAutoresizingMaskIntoConstraints = NO; grayLine.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:grayLine]; [self.contentView addSubview:grayLine];
UIView* guide = self.contentView;
self.cardLabel = CreateLabel(); self.cardLabel = CreateLabel();
[self.contentView addSubview:self.cardLabel]; [self.contentView addSubview:self.cardLabel];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.cardLabel ], grayLine, HorizontalConstraintsForViewsOnGuideWithShift(@[ self.cardLabel ], guide,
0); SideMargins);
self.cardNumberButton = self.cardNumberButton =
CreateButtonWithSelectorAndTarget(@selector(userDidTapCardNumber:), self); CreateButtonWithSelectorAndTarget(@selector(userDidTapCardNumber:), self);
[self.contentView addSubview:self.cardNumberButton]; [self.contentView addSubview:self.cardNumberButton];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.cardNumberButton ], HorizontalConstraintsForViewsOnGuideWithShift(@[ self.cardNumberButton ],
grayLine, 0); guide, 0);
self.cardholderButton = self.cardholderButton =
CreateButtonWithSelectorAndTarget(@selector(userDidTapCardInfo:), self); CreateButtonWithSelectorAndTarget(@selector(userDidTapCardInfo:), self);
[self.contentView addSubview:self.cardholderButton]; [self.contentView addSubview:self.cardholderButton];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.cardholderButton ], HorizontalConstraintsForViewsOnGuideWithShift(@[ self.cardholderButton ],
grayLine, 0); guide, 0);
// Expiration line. // Expiration line.
self.expirationMonthButton = self.expirationMonthButton =
CreateButtonWithSelectorAndTarget(@selector(userDidTapCardInfo:), self); CreateButtonWithSelectorAndTarget(@selector(userDidTapCardInfo:), self);
HorizontalConstraintsMarginForButtonWithWidth(self.expirationMonthButton,
ExpirationMarginWidth);
[self.contentView addSubview:self.expirationMonthButton]; [self.contentView addSubview:self.expirationMonthButton];
self.expirationYearButton = self.expirationYearButton =
CreateButtonWithSelectorAndTarget(@selector(userDidTapCardInfo:), self); CreateButtonWithSelectorAndTarget(@selector(userDidTapCardInfo:), self);
HorizontalConstraintsMarginForButtonWithWidth(self.expirationYearButton,
ExpirationMarginWidth);
[self.contentView addSubview:self.expirationYearButton]; [self.contentView addSubview:self.expirationYearButton];
UILabel* expirationSeparatorLabel = CreateLabel(); UILabel* expirationSeparatorLabel = CreateLabel();
expirationSeparatorLabel.text = @"/"; expirationSeparatorLabel.text = @"/";
...@@ -206,7 +201,7 @@ static const CGFloat ExpirationMarginWidth = 16.0; ...@@ -206,7 +201,7 @@ static const CGFloat ExpirationMarginWidth = 16.0;
self.expirationMonthButton, expirationSeparatorLabel, self.expirationMonthButton, expirationSeparatorLabel,
self.expirationYearButton self.expirationYearButton
], ],
grayLine, -ExpirationMarginWidth); guide, 0);
VerticalConstraintsSpacingForViewsInContainer( VerticalConstraintsSpacingForViewsInContainer(
@[ @[
...@@ -225,9 +220,9 @@ static const CGFloat ExpirationMarginWidth = 16.0; ...@@ -225,9 +220,9 @@ static const CGFloat ExpirationMarginWidth = 16.0;
// Horizontal constraints. // Horizontal constraints.
[grayLine.leadingAnchor constraintEqualToAnchor:safeArea.leadingAnchor [grayLine.leadingAnchor constraintEqualToAnchor:safeArea.leadingAnchor
constant:sideMargins], constant:SideMargins],
[safeArea.trailingAnchor constraintEqualToAnchor:grayLine.trailingAnchor [safeArea.trailingAnchor constraintEqualToAnchor:grayLine.trailingAnchor
constant:sideMargins], constant:SideMargins],
]]; ]];
} }
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_MANUAL_FILL_CELL_BUTTON_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_MANUAL_FILL_CELL_BUTTON_H_
#import <UIKit/UIKit.h>
// Buttons with a darker background in highlighted state.
@interface ManualFillCellButton : UIButton
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_MANUAL_FILL_CELL_BUTTON_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_cell_button.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/uicolor_manualfill.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ManualFillCellButton
- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];
auto animations = ^{
CGFloat alpha = highlighted ? 0.07 : 0;
self.backgroundColor = [UIColor colorWithWhite:0 alpha:alpha];
};
[UIView animateWithDuration:0.1
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:animations
completion:nil];
}
@end
...@@ -11,11 +11,6 @@ ...@@ -11,11 +11,6 @@
// |target|. // |target|.
UIButton* CreateButtonWithSelectorAndTarget(SEL action, id target); UIButton* CreateButtonWithSelectorAndTarget(SEL action, id target);
// Creates horizontal constraints for given |button| based on given |width| on
// both sides.
void HorizontalConstraintsMarginForButtonWithWidth(UIButton* button,
CGFloat width);
// Sets vertical constraints on firstBaselineAnchor for the button or label rows // Sets vertical constraints on firstBaselineAnchor for the button or label rows
// in |views| inside |container| starting at its topAnchor. Returns the applied // in |views| inside |container| starting at its topAnchor. Returns the applied
// constrainst to allow caller to deactivate them later. // constrainst to allow caller to deactivate them later.
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_cell_button.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/uicolor_manualfill.h" #import "ios/chrome/browser/ui/autofill/manual_fill/uicolor_manualfill.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h" #import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
...@@ -26,34 +27,33 @@ static const CGFloat MiddleSystemSpacingMultiplier = 1.83; ...@@ -26,34 +27,33 @@ static const CGFloat MiddleSystemSpacingMultiplier = 1.83;
// The multiplier for the base system spacing at the bottom margin. // The multiplier for the base system spacing at the bottom margin.
static const CGFloat BottomSystemSpacingMultiplier = 2.26; static const CGFloat BottomSystemSpacingMultiplier = 2.26;
// Top and bottom margins for buttons.
static const CGFloat ButtonVerticalMargin = 12;
// Left and right margins of the cell content and buttons.
static const CGFloat ButtonHorizontalMargin = 16;
} // namespace } // namespace
UIButton* CreateButtonWithSelectorAndTarget(SEL action, id target) { UIButton* CreateButtonWithSelectorAndTarget(SEL action, id target) {
UIButton* button = [UIButton buttonWithType:UIButtonTypeSystem]; UIButton* button = [ManualFillCellButton buttonWithType:UIButtonTypeCustom];
[button setTitleColor:UIColor.cr_manualFillTintColor [button setTitleColor:UIColor.cr_manualFillTintColor
forState:UIControlStateNormal]; forState:UIControlStateNormal];
button.translatesAutoresizingMaskIntoConstraints = NO; button.translatesAutoresizingMaskIntoConstraints = NO;
button.titleLabel.font = button.titleLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleBody]; [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
button.titleLabel.adjustsFontForContentSizeCategory = YES; button.titleLabel.adjustsFontForContentSizeCategory = YES;
button.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentLeading;
[button addTarget:target [button addTarget:target
action:action action:action
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
button.contentEdgeInsets =
UIEdgeInsetsMake(ButtonVerticalMargin, ButtonHorizontalMargin,
ButtonVerticalMargin, ButtonHorizontalMargin);
return button; return button;
} }
void HorizontalConstraintsMarginForButtonWithWidth(UIButton* button,
CGFloat width) {
[NSLayoutConstraint activateConstraints:@[
[button.leadingAnchor
constraintEqualToAnchor:button.titleLabel.leadingAnchor
constant:-width],
[button.trailingAnchor
constraintEqualToAnchor:button.titleLabel.trailingAnchor
constant:width],
]];
}
NSArray<NSLayoutConstraint*>* VerticalConstraintsSpacingForViewsInContainer( NSArray<NSLayoutConstraint*>* VerticalConstraintsSpacingForViewsInContainer(
NSArray<UIView*>* views, NSArray<UIView*>* views,
UIView* container) { UIView* container) {
...@@ -91,14 +91,27 @@ NSArray<NSLayoutConstraint*>* HorizontalConstraintsForViewsOnGuideWithShift( ...@@ -91,14 +91,27 @@ NSArray<NSLayoutConstraint*>* HorizontalConstraintsForViewsOnGuideWithShift(
[horizontalConstraints [horizontalConstraints
addObject:[view.leadingAnchor constraintEqualToAnchor:previousAnchor addObject:[view.leadingAnchor constraintEqualToAnchor:previousAnchor
constant:shift]]; constant:shift]];
[view setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
forAxis:
UILayoutConstraintAxisHorizontal];
[view setContentHuggingPriority:UILayoutPriorityDefaultHigh
forAxis:UILayoutConstraintAxisHorizontal];
previousAnchor = view.trailingAnchor; previousAnchor = view.trailingAnchor;
shift = 0; shift = 0;
} }
if (views.count > 0) { if (views.count > 0) {
[horizontalConstraints [horizontalConstraints
addObject:[views.lastObject.trailingAnchor addObject:[views.lastObject.trailingAnchor
constraintLessThanOrEqualToAnchor:guide.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor
constant:shift]]; constant:shift]];
// Give all remaining space to the last button, as per UX.
[views.lastObject
setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh
forAxis:
UILayoutConstraintAxisHorizontal];
[views.lastObject
setContentHuggingPriority:UILayoutPriorityDefaultLow
forAxis:UILayoutConstraintAxisHorizontal];
} }
[NSLayoutConstraint activateConstraints:horizontalConstraints]; [NSLayoutConstraint activateConstraints:horizontalConstraints];
return horizontalConstraints; return horizontalConstraints;
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
namespace { namespace {
// Left and right margins of the cell content. // Left and right margins of the cell content.
static const CGFloat sideMargins = 16; static const CGFloat SideMargins = 16;
} // namespace } // namespace
@interface ManualFillPasswordCell () @interface ManualFillPasswordCell ()
...@@ -142,24 +142,26 @@ static const CGFloat sideMargins = 16; ...@@ -142,24 +142,26 @@ static const CGFloat sideMargins = 16;
grayLine.translatesAutoresizingMaskIntoConstraints = NO; grayLine.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:grayLine]; [self.contentView addSubview:grayLine];
UIView* guide = self.contentView;
self.siteNameLabel = CreateLabel(); self.siteNameLabel = CreateLabel();
self.siteNameLabel.translatesAutoresizingMaskIntoConstraints = NO; self.siteNameLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.siteNameLabel.adjustsFontForContentSizeCategory = YES; self.siteNameLabel.adjustsFontForContentSizeCategory = YES;
[self.contentView addSubview:self.siteNameLabel]; [self.contentView addSubview:self.siteNameLabel];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.siteNameLabel ], HorizontalConstraintsForViewsOnGuideWithShift(@[ self.siteNameLabel ], guide,
grayLine, 0); SideMargins);
self.usernameButton = CreateButtonWithSelectorAndTarget( self.usernameButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapUsernameButton:), self); @selector(userDidTapUsernameButton:), self);
[self.contentView addSubview:self.usernameButton]; [self.contentView addSubview:self.usernameButton];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.usernameButton ], HorizontalConstraintsForViewsOnGuideWithShift(@[ self.usernameButton ], guide,
grayLine, 0); 0);
self.passwordButton = CreateButtonWithSelectorAndTarget( self.passwordButton = CreateButtonWithSelectorAndTarget(
@selector(userDidTapPasswordButton:), self); @selector(userDidTapPasswordButton:), self);
[self.contentView addSubview:self.passwordButton]; [self.contentView addSubview:self.passwordButton];
HorizontalConstraintsForViewsOnGuideWithShift(@[ self.passwordButton ], HorizontalConstraintsForViewsOnGuideWithShift(@[ self.passwordButton ], guide,
grayLine, 0); 0);
VerticalConstraintsSpacingForViewsInContainer( VerticalConstraintsSpacingForViewsInContainer(
@[ self.siteNameLabel, self.usernameButton, self.passwordButton ], @[ self.siteNameLabel, self.usernameButton, self.passwordButton ],
...@@ -175,9 +177,9 @@ static const CGFloat sideMargins = 16; ...@@ -175,9 +177,9 @@ static const CGFloat sideMargins = 16;
// Horizontal constraints. // Horizontal constraints.
[grayLine.leadingAnchor constraintEqualToAnchor:safeArea.leadingAnchor [grayLine.leadingAnchor constraintEqualToAnchor:safeArea.leadingAnchor
constant:sideMargins], constant:SideMargins],
[safeArea.trailingAnchor constraintEqualToAnchor:grayLine.trailingAnchor [safeArea.trailingAnchor constraintEqualToAnchor:grayLine.trailingAnchor
constant:sideMargins], constant:SideMargins],
]]; ]];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment