简体   繁体   中英

UITableViewRowAction change font and/or size

I have a UITableView with cells having some UITableViewRowActions. Our mockup uses a smaller font and a narrower UITableViewRowAction button. Is it possible to change the font and/or size of an UITableViewRowAction in any way?

Apple's documentation states it's impossible, and therefore I'm asking whether there is another way around.

UITableViewCell is made up of a backgroundView and a contentView , which lays over the backgroundView what you can do is add UIButton s as subView s to your backgroundView and add a UIPanGestureRecognizer over the cell. So when you pan the cell horizontally only contentView moves, UIButton s get exposed. So in cellForRowAtIndexPath

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *myCell;
        myCell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"YOUR_IDENTIFIER"];

   //adding button to a view that is added as the backgroundview
   UIView *cellBackgroundUtilityView=[[UIView   alloc]initWithFrame:myCell.frame];
   [cellBackgroundUtilityView addSubview:<your button>]
   [myCell setBackgroundView: cellBackgroundUtilityView]

   //adding a gesture recognizer
   UIPanGestureRecognizer *panningCell=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(yourPanningTableViewCellMethod:)];
   [panningCell setDelegate:self];
   [myCell addGestureRecognizer:panningCell];
}

when the gesture recognizer will be active this method will be called

-(void) yourPanningTableViewCellMethod:(id)sender
{
 // gesture recognizer is active
 UIPanGestureRecognizer* recognizer=(UIPanGestureRecognizer *) sender;
    UITableViewCell *tableCell=(UITableViewCell *)recognizer.view;

 //moving the contentView horizontally according to pan
 [tableCell.contentView setFrame:CGRectMake([recognizer translationInView:self.view].x, tableCell.contentView.frame.origin.y, tableCell.frame.size.width, tableCell.frame.size.height)];
}

when button's selector is called

-(void)yourBackgroundViewButtonWasPressed
{
 // button was pressed
 // move content view of the cell back to origin
 [tableCell.contentView setFrame:CGRectMake(0.0, tableCell.contentView.frame.origin.y, tableCell.frame.size.width, tableCell.frame.size.height)];

 //do your stuff
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM