我有一个分组UITableView
用户可以在其中进入编辑模式并从表中删除行。表格的每个单元格有两个UILabels
。当表格进入编辑模式时,自定义UILabels
向右推并超出单元格的右边界。
如果我使用标准cell.textLabel
,标签调整大小并保持在单元格的边界内。关于如何通过自定义执行此操作的想法UILabels
?
您需要实现并使用这两个 UITableViewDelegate 方法:
– tableView:willBeginEditingRowAtIndexPath:
– tableView:didEndEditingRowAtIndexPath:
在 willBegin 中,将 UILabel 框架设置为较小的宽度,并在 didEndEditing 中将宽度设置为正常大小。
例如,如果您的 UILabel 被推离边界 50 像素,则在您的方法中执行以下操作:
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *thisCell = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
CGRect newFrame = thisCell.someUILabel.frame;
newFrame.size.width -= 50;
thisCell.someUILabel.frame = newFrame;
}
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *thisCell = (UITableViewCell*)[tableView cellForRowAtIndexPath:indexPath];
CGRect newFrame = thisCell.someUILabel.frame;
newFrame.size.width += 50;
thisCell.someUILabel.frame = newFrame;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)