Skip to content

Commit e38d262

Browse files
committed
Added edge insets to MGSwipeButtons. Thanks to Zhukn1 for the idea.
1 parent 9088488 commit e38d262

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

MGSwipeTableCell/MGSwipeButton.h

+5
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ typedef BOOL(^MGSwipeButtonCallback)(MGSwipeTableCell * sender);
3030
*/
3131
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color;
3232
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding;
33+
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets;
3334
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback;
3435
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback;
36+
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets callback:(MGSwipeButtonCallback) callback;
3537
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color;
3638
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding;
39+
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets;
3740
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback;
3841
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback;
42+
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets callback:(MGSwipeButtonCallback) callback;
3943

4044
-(void) setPadding:(CGFloat) padding;
45+
-(void) setEdgeInsets:(UIEdgeInsets)insets;
4146
-(void) centerIconOverText;
4247

4348
@end

MGSwipeTableCell/MGSwipeButton.m

+30-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ +(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) c
1616

1717
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding
1818
{
19-
return [self buttonWithTitle:title icon:nil backgroundColor:color padding:padding];
19+
return [self buttonWithTitle:title icon:nil backgroundColor:color insets:UIEdgeInsetsMake(0, padding, 0, padding)];
20+
}
21+
22+
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets
23+
{
24+
return [self buttonWithTitle:title icon:nil backgroundColor:color insets:insets];
2025
}
2126

2227
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback
@@ -26,7 +31,12 @@ +(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) c
2631

2732
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback
2833
{
29-
return [self buttonWithTitle:title icon:nil backgroundColor:color padding:padding callback:callback];
34+
return [self buttonWithTitle:title icon:nil backgroundColor:color insets:UIEdgeInsetsMake(0, padding, 0, padding) callback:callback];
35+
}
36+
37+
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets callback:(MGSwipeButtonCallback) callback
38+
{
39+
return [self buttonWithTitle:title icon:nil backgroundColor:color insets:insets callback:callback];
3040
}
3141

3242
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color
@@ -36,7 +46,12 @@ +(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgrou
3646

3747
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding
3848
{
39-
return [self buttonWithTitle:title icon:icon backgroundColor:color padding:padding callback:nil];
49+
return [self buttonWithTitle:title icon:icon backgroundColor:color insets:UIEdgeInsetsMake(0, padding, 0, padding) callback:nil];
50+
}
51+
52+
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets
53+
{
54+
return [self buttonWithTitle:title icon:icon backgroundColor:color insets:insets callback:nil];
4055
}
4156

4257
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback
@@ -45,6 +60,11 @@ +(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgrou
4560
}
4661

4762
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback
63+
{
64+
return [self buttonWithTitle:title icon:icon backgroundColor:color insets:UIEdgeInsetsMake(0, padding, 0, padding) callback:callback];
65+
}
66+
67+
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color insets:(UIEdgeInsets) insets callback:(MGSwipeButtonCallback) callback
4868
{
4969
MGSwipeButton * button = [self buttonWithType:UIButtonTypeCustom];
5070
button.backgroundColor = color;
@@ -54,7 +74,7 @@ +(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgrou
5474
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
5575
[button setImage:icon forState:UIControlStateNormal];
5676
button.callback = callback;
57-
[button setPadding:padding];
77+
[button setEdgeInsets:insets];
5878
return button;
5979
}
6080

@@ -101,4 +121,10 @@ - (void)setButtonWidth:(CGFloat)buttonWidth
101121
}
102122
}
103123

124+
-(void) setEdgeInsets:(UIEdgeInsets)insets
125+
{
126+
self.contentEdgeInsets = insets;
127+
[self sizeToFit];
128+
}
129+
104130
@end

0 commit comments

Comments
 (0)