@@ -140,60 +140,71 @@ - (void)configureButtonsIfNeeded
140140
141141- (UIButton *)buttonForIndex : (NSInteger )index previousButtonMinX : (CGFloat)previousMinX
142142{
143- UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom] ;
143+ UIButton *button = nil ;
144144
145- if ([self .dataSource respondsToSelector: @selector (swipeableCell:backgroundColorForButtonAtIndex: )]) {
146- // Set background color from data source
147- button.backgroundColor = [self .dataSource swipeableCell: self backgroundColorForButtonAtIndex: index];
145+ /* The datasource implements buttonForIndex. Let's use custom buttom */
146+ if ([self .dataSource respondsToSelector: @selector (swipeableCell:buttonForIndex: )]) {
147+
148+ button = [self .dataSource swipeableCell: self buttonForIndex: index];
149+
150+ /* Lets generate the button */
148151 } else {
149- // Use default colors
150- if (index == 0 ) {
151- button.backgroundColor = [UIColor redColor ];
152+
153+ button = [UIButton buttonWithType: UIButtonTypeCustom];
154+
155+ if ([self .dataSource respondsToSelector: @selector (swipeableCell:titleForButtonAtIndex: )]) {
156+ // use given title
157+ [button setTitle: [self .dataSource swipeableCell: self titleForButtonAtIndex: index] forState: UIControlStateNormal];
152158 } else {
153- button.backgroundColor = [UIColor lightGrayColor ];
159+ // Default to empty title
160+ [button setTitle: @" " forState: UIControlStateNormal];
154161 }
155- }
156-
157- if ([self .dataSource respondsToSelector: @selector (swipeableCell:titleForButtonAtIndex: )]) {
158- // use given title
159- [button setTitle: [self .dataSource swipeableCell: self titleForButtonAtIndex: index] forState: UIControlStateNormal];
160- } else {
161- // Default to empty title
162- [button setTitle: @" " forState: UIControlStateNormal];
163- }
164-
165- if ([self .dataSource respondsToSelector: @selector (swipeableCell:imageForButtonAtIndex: )]) {
166- // Use the image, if it exists
167- UIImage *iconImage = [self .dataSource swipeableCell: self imageForButtonAtIndex: index];
168- if (iconImage) {
169- [button setImage: [iconImage imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate] forState: UIControlStateNormal];
162+
163+ if ([self .dataSource respondsToSelector: @selector (swipeableCell:imageForButtonAtIndex: )]) {
164+ // Use the image, if it exists
165+ UIImage *iconImage = [self .dataSource swipeableCell: self imageForButtonAtIndex: index];
166+ if (iconImage) {
167+ [button setImage: [iconImage imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate] forState: UIControlStateNormal];
168+ }
169+ }
170+
171+ if ([self .dataSource respondsToSelector: @selector (swipeableCell:tintColorForButtonAtIndex: )]) {
172+ // Use the given tint color.
173+ button.tintColor = [self .dataSource swipeableCell: self tintColorForButtonAtIndex: index];
174+ } else {
175+ // Default to white
176+ button.tintColor = [UIColor whiteColor ];
177+ }
178+
179+ // Add 8pt of padding on the left and right.
180+ [button setContentEdgeInsets: UIEdgeInsetsMake (0 , 8 , 0 , 8 )];
181+
182+ if ([self .dataSource respondsToSelector: @selector (swipeableCell:fontForButtonAtIndex: )]) {
183+ // Set font if provided.
184+ button.titleLabel .font = [self .dataSource swipeableCell: self fontForButtonAtIndex: index];
185+ }
186+
187+ // Size the button to fit the contents
188+ [button sizeToFit ];
189+
190+ CGFloat appleRecommendedMinimumTouchPointWidth = 44 .0f ;
191+ if (button.frame .size .width < appleRecommendedMinimumTouchPointWidth) {
192+ CGRect frame = button.frame ;
193+ frame.size .width = appleRecommendedMinimumTouchPointWidth;
194+ button.frame = frame;
195+ }
196+
197+ if ([self .dataSource respondsToSelector: @selector (swipeableCell:backgroundColorForButtonAtIndex: )]) {
198+ // Set background color from data source
199+ button.backgroundColor = [self .dataSource swipeableCell: self backgroundColorForButtonAtIndex: index];
200+ } else {
201+ // Use default colors
202+ if (index == 0 ) {
203+ button.backgroundColor = [UIColor redColor ];
204+ } else {
205+ button.backgroundColor = [UIColor lightGrayColor ];
206+ }
170207 }
171- }
172-
173- if ([self .dataSource respondsToSelector: @selector (swipeableCell:tintColorForButtonAtIndex: )]) {
174- // Use the given tint color.
175- button.tintColor = [self .dataSource swipeableCell: self tintColorForButtonAtIndex: index];
176- } else {
177- // Default to white
178- button.tintColor = [UIColor whiteColor ];
179- }
180-
181- // Add 8pt of padding on the left and right.
182- [button setContentEdgeInsets: UIEdgeInsetsMake (0 , 8 , 0 , 8 )];
183-
184- if ([self .dataSource respondsToSelector: @selector (swipeableCell:fontForButtonAtIndex: )]) {
185- // Set font if provided.
186- button.titleLabel .font = [self .dataSource swipeableCell: self fontForButtonAtIndex: index];
187- }
188-
189- // Size the button to fit the contents
190- [button sizeToFit ];
191-
192- CGFloat appleRecommendedMinimumTouchPointWidth = 44 .0f ;
193- if (button.frame .size .width < appleRecommendedMinimumTouchPointWidth) {
194- CGRect frame = button.frame ;
195- frame.size .width = appleRecommendedMinimumTouchPointWidth;
196- button.frame = frame;
197208 }
198209
199210 // Update the origin and size to make sure that everything is the size it needs to be
0 commit comments