[英]UITableViewRowAction change font and/or size
我有一個帶有單元格的UITableView的UITableViewRowActions。 我們的模型使用較小的字體和較窄的UITableViewRowAction按鈕。 是否可以通過任何方式更改UITableViewRowAction的字體和/或大小?
Apple的文檔指出這是不可能的,因此我想問是否還有另一種解決方法。
UITableViewCell
由一個backgroundView
和一個contentView
,它們位於backgroundView
,您可以做的是將UIButton
作為subView
添加到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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.