如何在使用默认UITableViewCell
时将UITableViewCell
textLabel位置固定在滑动上。
在滑动textLabel
上,文字会在屏幕左侧和外部显示。
相关代码:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return YES if you want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//code related to delete row
}
}
检查以下图片以便清楚了解:
在滑动之前:
滑动后:
答案 0 :(得分:0)
- (void)layoutSubviews
{
[super layoutSubviews];
CGSize size = self.bounds.size;
CGRect frame = CGRectMake(4.0f, 4.0f, size.width, size.height);
self.textLabel.frame = frame;
self.textLabel.contentMode = UIViewContentModeScaleAspectFit;
}
覆盖此方法......
答案 1 :(得分:0)
我认为你在刷卡时会移动contentView,所以试试这个:
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect frame = CGRectOffset(self.textLabel.frame,0-self.contentView.frame.x,0);
self.textLabel.frame = frame;
}
答案 2 :(得分:-1)
请尝试这个:
#pragma mark- swipeable cell
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.frame=CGRectMake(30, 2, 50, 10);
UITableViewRowAction *unlink_button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
[self.accountsTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
cell.textLabel.frame=CGRectMake(0, 2, 50, 10);
[self deleteFunction];
}];
unlink_button.backgroundColor = [UIColor redColor]; //arbitrary color
return @[unlink_button];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// you need to implement this method too or nothing will work:
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}