【问题标题】:UITableViewRowAction change font and/or sizeUITableViewRowAction 更改字体和/或大小
【发布时间】:2015-08-12 08:33:11
【问题描述】:

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

Apple's documentation 表示这是不可能的,因此我想问是否有其他方法。

【问题讨论】:

    标签: ios uitableview ios8 uitableviewrowaction


    【解决方案1】:

    UITableViewCellbackgroundViewcontentView 组成,覆盖backgroundView 您可以将UIButtons 作为subViews 添加到您的backgroundView 并添加一个UIPanGestureRecognizer 在单元格上方。因此,当您水平平移单元格时,只有 contentView 移动,UIButtons 会暴露。所以在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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 2011-06-25
      • 2015-05-10
      • 1970-01-01
      • 2023-02-25
      相关资源
      最近更新 更多