Skip to content

Commit

Permalink
Fixed issue #14: added optional padding parameter to convenience MGSw…
Browse files Browse the repository at this point in the history
…ipeButton static constructors
  • Loading branch information
Imanol Fernandez authored and Imanol Fernandez committed Sep 25, 2014
1 parent a5ace36 commit 5efd741
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
10 changes: 6 additions & 4 deletions MGSwipeTableCell/MGSwipeButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ typedef BOOL(^MGSwipeButtonCallback)(MGSwipeTableCell * sender);
* Convenience static constructors
*/
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color width:(NSInteger) width;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color width:(NSInteger) width callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color width:(NSInteger) width;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color width:(NSInteger) width callback:(MGSwipeButtonCallback) callback;
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback;

-(void) setPadding:(CGFloat) padding;

@end
33 changes: 15 additions & 18 deletions MGSwipeTableCell/MGSwipeButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,45 @@ +(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) c
return [MGSwipeButton buttonWithTitle:title icon:nil backgroundColor:color];
}

+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color width:(NSInteger) width
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding
{
return [MGSwipeButton buttonWithTitle:title icon:nil backgroundColor:color width:width];
return [MGSwipeButton buttonWithTitle:title icon:nil backgroundColor:color padding:padding];
}

+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback
{
return [MGSwipeButton buttonWithTitle:title icon:nil backgroundColor:color callback:callback];
}

+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color width:(NSInteger) width callback:(MGSwipeButtonCallback) callback
+(instancetype) buttonWithTitle:(NSString *) title backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback
{
return [MGSwipeButton buttonWithTitle:title icon:nil backgroundColor:color width:width callback:callback];
return [MGSwipeButton buttonWithTitle:title icon:nil backgroundColor:color padding:padding callback:callback];
}

+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color
{
return [MGSwipeButton buttonWithTitle:title icon:icon backgroundColor:color callback:nil];
}

+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color width:(NSInteger) width
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding
{
return [MGSwipeButton buttonWithTitle:title icon:icon backgroundColor:color width:width callback:nil];
return [MGSwipeButton buttonWithTitle:title icon:icon backgroundColor:color padding:padding callback:nil];
}

+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color callback:(MGSwipeButtonCallback) callback
{
return [MGSwipeButton buttonWithTitle:title icon:icon backgroundColor:color width:0 callback:callback];
return [MGSwipeButton buttonWithTitle:title icon:icon backgroundColor:color padding:10 callback:callback];
}

+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color width:(NSInteger) width callback:(MGSwipeButtonCallback) callback
+(instancetype) buttonWithTitle:(NSString *) title icon:(UIImage*) icon backgroundColor:(UIColor *) color padding:(NSInteger) padding callback:(MGSwipeButtonCallback) callback
{
MGSwipeButton * button = [MGSwipeButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = color;
[button setTitle:title forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setImage:icon forState:UIControlStateNormal];
button.callback = callback;
[button sizeToFit];
CGRect frame = button.frame;
if (width) {
frame.size.width = width;
}
else {
frame.size.width += 10; //default padding
frame.size.width = MAX(50, frame.size.width); //initial min size
}
button.frame = frame;
[button setPadding:padding];
return button;
}

Expand All @@ -73,4 +64,10 @@ -(BOOL) callMGSwipeConvenienceCallback: (MGSwipeTableCell *) sender
return NO;
}

-(void) setPadding:(CGFloat) padding
{
self.contentEdgeInsets = UIEdgeInsetsMake(0, padding, 0, padding);
[self sizeToFit];
}

@end
2 changes: 1 addition & 1 deletion demo/MGSwipeDemo/DemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ -(NSArray *) createLeftButtons: (int) number
UIImage * icons[3] = {[UIImage imageNamed:@"check.png"], [UIImage imageNamed:@"fav.png"], [UIImage imageNamed:@"menu.png"]};
for (int i = 0; i < number; ++i)
{
MGSwipeButton * button = [MGSwipeButton buttonWithTitle:@"" icon:icons[i] backgroundColor:colors[i] width:55 callback:^BOOL(MGSwipeTableCell * sender){
MGSwipeButton * button = [MGSwipeButton buttonWithTitle:@"" icon:icons[i] backgroundColor:colors[i] padding:15 callback:^BOOL(MGSwipeTableCell * sender){
NSLog(@"Convenience callback received (left).");
return YES;
}];
Expand Down

0 comments on commit 5efd741

Please sign in to comment.