UITableViewRowAction更改字体和/或大小

时间:2015-08-12 08:33:12

标签: ios uitableview ios8 uitableviewrowaction

我有一个带有一些UITableViewRowActions的单元格的UITableView。我们的模型使用较小的字体和较窄的UITableViewRowAction按钮。是否可以以任何方式更改UITableViewRowAction的字体和/或大小?

Apple's documentation声明这是不可能的,因此我在问是否还有其他办法。

1 个答案:

答案 0 :(得分:0)

UITableViewCellbackgroundViewcontentView组成,它覆盖backgroundView您可以执行的操作是将UIButton添加为{subView 1}}到你的backgroundView并在单元格上添加UIPanGestureRecognizer。因此,当您仅水平平移单元格contentView移动时,UIButton会被暴露。所以在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];
}

当手势识别器处于活动状态时,将调用此方法

-(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)];
}

当调用按钮的选择器时

-(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
}