Skip to content

Commit

Permalink
Prevent STPPaymentMethodTableViewCell.titleLabel from overlapping c…
Browse files Browse the repository at this point in the history
…heckmark (#952)

Previous layout code allowed the `titleLabel` to be as wide as it wanted, even if
that ran offscreen. Fixing it to explicitly constrain the `titleLabel` to be between
the `leftIcon` and `checkmarkIcon`, with horizontal spacing of `padding`.

Instead of asking UIKit to calculate the height that the `titleLabel` should be, just use
the full height of the cell. We get the same vertical centering, and similarly prevents
the label from exceeding the bounds of the cell.

The snapshot tests do show slight differences in how the `titleLabel` renders. I believe
it's *now* pixel aligning the text. When I compare before/after, especially on something
like the `E` in `Ending In` (it's true of all the letters, but really apparent on `E`),
the old snapshot has anti-aliased top/bottoms, where the new snapshot has crisp lines.
This is subtle enough that I hadn't noticed it previously, but I think it's a nice,
unexpected bonus.

Fixes #948
  • Loading branch information
danj-stripe authored May 30, 2018
1 parent 3881229 commit c2880e3
Show file tree
Hide file tree
Showing 12 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Fixes payment method label overlapping the checkmark, for Amex on small devices [#952](https://github.com/stripe/stripe-ios/pull/952)

## 13.0.2 2018-05-24
* Makes iDEAL `name` parameter optional, also accepts empty string as `nil` [#940](https://github.com/stripe/stripe-ios/pull/940)
* Adjusts scroll view content offset behavior when focusing on a text field [#943](https://github.com/stripe/stripe-ios/pull/943)
Expand Down
11 changes: 7 additions & 4 deletions Stripe/STPPaymentMethodTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ - (void)layoutSubviews {
[self.leftIcon sizeToFit];
self.leftIcon.center = CGPointMake(padding + (iconWidth / 2.0f), midY);

// Title label
[self.titleLabel sizeToFit];
self.titleLabel.center = CGPointMake(padding + iconWidth + padding + CGRectGetMidX(self.titleLabel.bounds), midY);

// Checkmark icon
self.checkmarkIcon.frame = CGRectMake(0.0, 0.0, 14.0f, 14.0f);
self.checkmarkIcon.center = CGPointMake(CGRectGetWidth(self.bounds) - padding - CGRectGetMidX(self.checkmarkIcon.bounds), midY);

// Title label
CGRect labelFrame = self.bounds;
// not every icon is `iconWidth` wide, but give them all the same amount of space:
labelFrame.origin.x = padding + iconWidth + padding;
labelFrame.size.width = CGRectGetMinX(self.checkmarkIcon.frame) - padding - labelFrame.origin.x;
self.titleLabel.frame = labelFrame;
}

- (void)configureForNewCardRowWithTheme:(STPTheme *)theme {
Expand Down
Binary file modified ...mages_64/STPPaymentContextSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified ...mages_64/STPPaymentContextSnapshotTests/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c2880e3

Please sign in to comment.