UITableViewRowAction 更改字体 and/or 大小
UITableViewRowAction change font and/or size
我有一个 UITableView,其中的单元格具有一些 UITableViewRowActions。我们的模型使用较小的字体和较窄的 UITableViewRowAction 按钮。是否可以以任何方式更改 UITableViewRowAction 的字体 and/or 大小?
Apple's documentation 声明这是不可能的,因此我想问一下是否还有其他解决方法。
UITableViewCell
由 backgroundView
和 contentView
组成,它位于 backgroundView
之上,您可以添加 UIButton
作为subView
s 到您的 backgroundView
并在单元格上添加 UIPanGestureRecognizer
。因此,当您水平平移单元格时,只有 contentView
移动,UIButton
s 就会暴露。所以在 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
}
我有一个 UITableView,其中的单元格具有一些 UITableViewRowActions。我们的模型使用较小的字体和较窄的 UITableViewRowAction 按钮。是否可以以任何方式更改 UITableViewRowAction 的字体 and/or 大小?
Apple's documentation 声明这是不可能的,因此我想问一下是否还有其他解决方法。
UITableViewCell
由 backgroundView
和 contentView
组成,它位于 backgroundView
之上,您可以添加 UIButton
作为subView
s 到您的 backgroundView
并在单元格上添加 UIPanGestureRecognizer
。因此,当您水平平移单元格时,只有 contentView
移动,UIButton
s 就会暴露。所以在 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
}