@@ -54,16 +54,21 @@ @implementation MGSwipeButtonsView
54
54
55
55
#pragma mark Layout
56
56
57
- -(instancetype ) initWithButtons : (NSArray *) buttonsArray direction : (MGSwipeDirection) direction
57
+ -(instancetype ) initWithButtons : (NSArray *) buttonsArray direction : (MGSwipeDirection) direction differentWidth : ( BOOL ) differentWidth
58
58
{
59
+ CGFloat containerWidth = 0 ;
59
60
CGSize maxSize = CGSizeZero ;
60
61
61
62
for (UIView * button in buttonsArray) {
62
- maxSize.width += button.bounds .size .width ;
63
+ containerWidth += button.bounds .size .width ;
64
+ maxSize.width = MAX (maxSize.width , button.bounds .size .width );
63
65
maxSize.height = MAX (maxSize.height , button.bounds .size .height );
64
66
}
67
+ if (!differentWidth) {
68
+ containerWidth = maxSize.width * buttonsArray.count ;
69
+ }
65
70
66
- if (self = [super initWithFrame: CGRectMake (0 , 0 , maxSize.width , maxSize.height)]) {
71
+ if (self = [super initWithFrame: CGRectMake (0 , 0 , containerWidth , maxSize.height)]) {
67
72
_fromLeft = direction == MGSwipeDirectionLeftToRight;
68
73
_container = [[UIView alloc ] initWithFrame: self .bounds];
69
74
_container.clipsToBounds = YES ;
@@ -74,6 +79,9 @@ -(instancetype) initWithButtons:(NSArray*) buttonsArray direction:(MGSwipeDirect
74
79
if ([button isKindOfClass: [UIButton class ]]) {
75
80
[(UIButton *)button addTarget: self action: @selector (buttonClicked: ) forControlEvents: UIControlEventTouchUpInside];
76
81
}
82
+ if (!differentWidth) {
83
+ button.frame = CGRectMake (0 , 0 , maxSize.width , maxSize.height );
84
+ }
77
85
button.autoresizingMask = UIViewAutoresizingFlexibleHeight;
78
86
[_container insertSubview: button atIndex: _fromLeft ? 0: _container.subviews.count];
79
87
}
@@ -522,14 +530,14 @@ -(void) createSwipeViewIfNeeded
522
530
523
531
[self fetchButtonsIfNeeded ];
524
532
if (!_leftView && _leftButtons.count > 0 ) {
525
- _leftView = [[MGSwipeButtonsView alloc ] initWithButtons: _leftButtons direction: MGSwipeDirectionLeftToRight];
533
+ _leftView = [[MGSwipeButtonsView alloc ] initWithButtons: _leftButtons direction: MGSwipeDirectionLeftToRight differentWidth: _allowsButtonsWithDifferentWidth ];
526
534
_leftView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
527
535
_leftView.cell = self;
528
536
_leftView.frame = CGRectMake (-_leftView.bounds .size .width , 0 , _leftView.bounds .size .width , _swipeOverlay.bounds .size .height );
529
537
[_swipeOverlay addSubview: _leftView];
530
538
}
531
539
if (!_rightView && _rightButtons.count > 0 ) {
532
- _rightView = [[MGSwipeButtonsView alloc ] initWithButtons: _rightButtons direction: MGSwipeDirectionRightToLeft];
540
+ _rightView = [[MGSwipeButtonsView alloc ] initWithButtons: _rightButtons direction: MGSwipeDirectionRightToLeft differentWidth: _allowsButtonsWithDifferentWidth ];
533
541
_rightView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
534
542
_rightView.cell = self;
535
543
_rightView.frame = CGRectMake (_swipeOverlay.bounds .size .width , 0 , _rightView.bounds .size .width , _swipeOverlay.bounds .size .height );
0 commit comments