@@ -642,9 +642,16 @@ - (void)removeErrorLabel
642642- (CGRect)textRectForBounds : (CGRect)bounds
643643{
644644 CGRect superRect = [super textRectForBounds: bounds];
645- CGRect rect = CGRectMake (superRect.origin .x + self.textPadding .width ,
645+ CGRect rightRect = [super rightViewRectForBounds: bounds];
646+ BOOL hasLeftView = [self leftViewRectForBounds: bounds].size .width > 0 ;
647+ BOOL hasRightView = [self rightViewRectForBounds: bounds].size .width > 0 ;
648+
649+ CGFloat leftPadding = hasLeftView ? 0 : self.textPadding .width ;
650+ CGFloat rightPadding = hasRightView ? rightRect.size .width : self.textPadding .width * 2 ;
651+
652+ CGRect rect = CGRectMake (superRect.origin .x + leftPadding,
646653 [self adjustedYPositionForTextRect ],
647- superRect.size .width - ( 2.0 * self. textPadding . width ) ,
654+ superRect.size .width - rightPadding ,
648655 self.font .lineHeight );
649656 self.textRect = rect;
650657 return rect;
@@ -680,6 +687,7 @@ - (CGRect)clearButtonRectForBounds:(CGRect)bounds
680687- (CGRect)rightViewRectForBounds : (CGRect)bounds
681688{
682689 CGRect rightViewRect = [super rightViewRectForBounds: bounds];
690+ rightViewRect.origin .x = rightViewRect.origin .x - self.textPadding .width ;
683691 rightViewRect.origin .y = CGRectGetMidY (_textRect) - (rightViewRect.size .height / 2 .0f );
684692
685693 return rightViewRect;
@@ -688,6 +696,7 @@ - (CGRect)rightViewRectForBounds:(CGRect)bounds
688696- (CGRect)leftViewRectForBounds : (CGRect)bounds
689697{
690698 CGRect leftViewRect = [super leftViewRectForBounds: bounds];
699+ leftViewRect.origin .x = self.textPadding .width ;
691700 leftViewRect.origin .y = CGRectGetMidY (_textRect) - (leftViewRect.size .height / 2 .0f );
692701
693702 return leftViewRect;
0 commit comments