@@ -673,57 +673,71 @@ - (void)layoutSubviews
673673 CGFloat offset = 8 .0f ;
674674 if (self.frame .size .width > self.frame .size .height )
675675 {
676- if (buttons.count == 1 )
677- {
676+ _cancelButton.frame = CGRectMake (0 , 0 , 49 , 49 );
677+
678+ CGFloat leftEdge = _cancelButton.frame .size .width ;
679+ CGFloat rightEdge = 0 .0f ;
680+
681+ if (_starsDoneButton != nil ) {
682+ CGSize buttonSize = [_starsDoneButton updateCount: _sendPaidMessageStars];
683+ rightEdge = buttonSize.width + 2 .0f ;
684+ [_starsDoneButton updateFrame: CGRectMake (self .frame.size.width - rightEdge, 2 .0f , buttonSize.width, buttonSize.height)];
685+ } else {
686+ rightEdge = _cancelButton.frame .size .width ;
687+ }
688+
689+ CGFloat availableWidth = self.frame .size .width - leftEdge - rightEdge;
690+ CGFloat startX = leftEdge;
691+ CGFloat sideOffset = 5 .0f ;
692+
693+ if (buttons.count == 1 ) {
678694 UIView *button = buttons.firstObject ;
679- button.frame = CGRectMake (CGFloor (self.frame .size .width / 2 - button.frame .size .width / 2 ), offset, button.frame .size .width , button.frame .size .height );
695+ CGFloat buttonX = startX + (availableWidth - button.frame .size .width ) / 2 ;
696+ button.frame = CGRectMake (buttonX, offset, button.frame .size .width , button.frame .size .height );
680697 }
681- else if (buttons.count == 2 )
682- {
698+ else if (buttons.count == 2 ) {
683699 UIView *leftButton = buttons.firstObject ;
684700 UIView *rightButton = buttons.lastObject ;
685701
686- leftButton.frame = CGRectMake (CGFloor (self.frame .size .width / 5 * 2 - 5 - leftButton.frame .size .width / 2 ), offset, leftButton.frame .size .width , leftButton.frame .size .height );
687- rightButton.frame = CGRectMake (CGCeil (self.frame .size .width - leftButton.frame .origin .x - rightButton.frame .size .width ), offset, rightButton.frame .size .width , rightButton.frame .size .height );
702+ CGFloat leftButtonX = startX + availableWidth / 3 - leftButton.frame .size .width / 2 - sideOffset;
703+ CGFloat rightButtonX = startX + 2 * availableWidth / 3 - rightButton.frame .size .width / 2 + sideOffset;
704+
705+ leftButton.frame = CGRectMake (leftButtonX, offset, leftButton.frame .size .width , leftButton.frame .size .height );
706+ rightButton.frame = CGRectMake (rightButtonX, offset, rightButton.frame .size .width , rightButton.frame .size .height );
688707 }
689- else if (buttons.count == 3 )
690- {
708+ else if (buttons.count == 3 ) {
691709 UIView *leftButton = buttons.firstObject ;
692710 UIView *centerButton = [buttons objectAtIndex: 1 ];
693711 UIView *rightButton = buttons.lastObject ;
694712
695- centerButton. frame = CGRectMake ( CGFloor (self. frame . size . width / 2 - centerButton .frame .size .width / 2 ), offset, centerButton. frame . size . width , centerButton. frame . size . height ) ;
696-
697- leftButton. frame = CGRectMake ( CGFloor (self. frame . size . width / 6 * 2 - 10 - leftButton .frame .size .width / 2 ), offset, leftButton. frame . size . width , leftButton. frame . size . height ) ;
713+ CGFloat leftButtonX = startX + availableWidth / 4 - leftButton .frame .size .width / 2 - sideOffset ;
714+ CGFloat centerButtonX = startX + availableWidth / 2 - centerButton. frame . size . width / 2 ;
715+ CGFloat rightButtonX = startX + 3 * availableWidth / 4 - rightButton .frame .size .width / 2 + sideOffset ;
698716
699- rightButton.frame = CGRectMake (CGCeil (self.frame .size .width - leftButton.frame .origin .x - rightButton.frame .size .width ), offset, rightButton.frame .size .width , rightButton.frame .size .height );
717+ leftButton.frame = CGRectMake (leftButtonX, offset, leftButton.frame .size .width , leftButton.frame .size .height );
718+ centerButton.frame = CGRectMake (centerButtonX, offset, centerButton.frame .size .width , centerButton.frame .size .height );
719+ rightButton.frame = CGRectMake (rightButtonX, offset, rightButton.frame .size .width , rightButton.frame .size .height );
700720 }
701- else if (buttons.count == 4 )
702- {
721+ else if (buttons.count == 4 ) {
703722 UIView *leftButton = buttons.firstObject ;
704723 UIView *centerLeftButton = [buttons objectAtIndex: 1 ];
705724 UIView *centerRightButton = [buttons objectAtIndex: 2 ];
706725 UIView *rightButton = buttons.lastObject ;
707726
708- leftButton.frame = CGRectMake (CGFloor (self.frame .size .width / 8 * 2 - 3 - leftButton.frame .size .width / 2 ), offset, leftButton.frame .size .width , leftButton.frame .size .height );
709-
710- centerLeftButton.frame = CGRectMake (CGFloor (self.frame .size .width / 10 * 4 + 5 - centerLeftButton.frame .size .width / 2 ), offset, centerLeftButton.frame .size .width , centerLeftButton.frame .size .height );
711-
712- centerRightButton.frame = CGRectMake (CGCeil (self.frame .size .width - centerLeftButton.frame .origin .x - centerRightButton.frame .size .width ), offset, centerRightButton.frame .size .width , centerRightButton.frame .size .height );
727+ CGFloat leftButtonX = startX + availableWidth / 5 - leftButton.frame .size .width / 2 - sideOffset;
728+ CGFloat centerLeftButtonX = startX + 2 * availableWidth / 5 - centerLeftButton.frame .size .width / 2 - TGScreenPixelFloor (sideOffset / 2.0 );
729+ CGFloat centerRightButtonX = startX + 3 * availableWidth / 5 - centerRightButton.frame .size .width / 2 + TGScreenPixelFloor (sideOffset / 2.0 );
730+ CGFloat rightButtonX = startX + 4 * availableWidth / 5 - rightButton.frame .size .width / 2 + sideOffset;
713731
714- rightButton.frame = CGRectMake (CGCeil (self.frame .size .width - leftButton.frame .origin .x - rightButton.frame .size .width ), offset, rightButton.frame .size .width , rightButton.frame .size .height );
732+ leftButton.frame = CGRectMake (leftButtonX, offset, leftButton.frame .size .width , leftButton.frame .size .height );
733+ centerLeftButton.frame = CGRectMake (centerLeftButtonX, offset, centerLeftButton.frame .size .width , centerLeftButton.frame .size .height );
734+ centerRightButton.frame = CGRectMake (centerRightButtonX, offset, centerRightButton.frame .size .width , centerRightButton.frame .size .height );
735+ rightButton.frame = CGRectMake (rightButtonX, offset, rightButton.frame .size .width , rightButton.frame .size .height );
715736 }
716737
717- _cancelButton.frame = CGRectMake (0 , 0 , 49 , 49 );
718738 CGFloat offset = 49 .0f ;
719739 if (_doneButton.frame .size .width > 49 .0f )
720740 offset = 60 .0f ;
721-
722- if (_starsDoneButton != nil ) {
723- CGSize buttonSize = [_starsDoneButton updateCount: _sendPaidMessageStars];
724- [_starsDoneButton updateFrame: CGRectMake (self .frame.size.width - buttonSize.width - 2.0 , 49 .0f - offset + 2 .0f , buttonSize.width, buttonSize.height)];
725- }
726-
727741 _doneButton.frame = CGRectMake (self.frame .size .width - offset, 49 .0f - offset, _doneButton.frame .size .width , _doneButton.frame .size .height );
728742
729743 _infoLabel.frame = CGRectMake (49 .0f + 10 .0f , 0 .0f , self.frame .size .width - (49 .0f + 10 .0f ) * 2 .0f , 49 .0f );
0 commit comments