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