hacker
hacker

Reputation: 8957

Managing Equall width in UITableViewRowAction buttons?

I had an IPHone application in which i am trying to use UITableViewRowAction with edit,Copy and delete options,it was working well all the way.The problem is i want to make it with equal width for all buttons and having underlined titles.I am doing like this

`UITableViewRowAction *EditAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Edit” handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){

        indextodelete=(int)indexPath.section;
        // maybe show an action sheet with more options
           [self.mTableView setEditing:NO];
    }];
    EditAction.backgroundColor = [UIColor GreenColor]];`

Can anybody help me?

Upvotes: 0

Views: 1738

Answers (2)

Gurmeet Khalsa
Gurmeet Khalsa

Reputation: 136

I know its weird but there is no property as of now to set the height or width of the row action buttons. Height of the buttons is same as height of the row. Width of the button is based on the text for title. Only workaround is to add empty space on both side of the title:

UITableViewRowAction(style: .Destructive, title: "  Delete  ")

Upvotes: 1

sambol
sambol

Reputation: 324

Below is the interface in UIKit for UITableViewRowAction. It doesn't look like there is a size. You could do it all yourself, but it's time consuming: http://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views.

What I did is just add spaces to the title until the buttons looked the same size (i.e. @"___Delete_____").

NS_CLASS_AVAILABLE_IOS(8_0) @interface UITableViewRowAction : NSObject <NSCopying>

+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(NSString *)title   handler:(void (^)(UITableViewRowAction *action, NSIndexPath *indexPath))handler;

@property (nonatomic, readonly) UITableViewRowActionStyle style;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) UIColor *backgroundColor; // default background color is dependent on style
@property (nonatomic, copy) UIVisualEffect* backgroundEffect;

@end

Upvotes: 3

Related Questions