虽然我同意 Antonis 对 iOS 未来可能发生变化的担忧,但我最终还是采用了我在问题中描述的方法,只是在系统附件上用不同的颜色重新绘制了附件。原因是这个视图带有拖动单元格的交互;如果我试图将其移除并自己绘制,我将无法移动单元格。我扩展了 MSCellAccessory 库。这是我的 willDisplayCell 方法:
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
for(UIView* view in cell.subviews)
{
if([[[view class] description] isEqualToString:@"UITableViewCellReorderControl"])
{
MSCellAccessory *overlayControl = [MSCellAccessory accessoryWithType:FLAT_REORDER_CONTROL color:[UIColor colorWithRed:0.353 green:0.153 blue:0.035 alpha:1.0]];
[overlayControl setFrame:CGRectMake(0, 0, view.bounds.size.width, view.bounds.size.height)];
[view addSubview:overlayControl];
}
}
}
这是我对 MSCellAccessory.m 的扩展:
#define FLAT_REORDER_CONTROL_START_X CGRectGetMinX(self.bounds)+15
#define FLAT_REORDER_CONTROL_END_X CGRectGetMaxX(self.bounds)-15
#define FLAT_REORDER_CONTROL_STROKE_1_Y 19
#define FLAT_REORDER_CONTROL_STROKE_2_Y 22.5
#define FLAT_REORDER_CONTROL_STROKE_3_Y 26
#define FLAT_REORDER_CONTROL_STROKE_WIDTH 2
和
} else if(_accType == FLAT_REORDER_CONTROL) {
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(ctx, FLAT_REORDER_CONTROL_START_X, FLAT_REORDER_CONTROL_STROKE_1_Y);
CGContextAddLineToPoint(ctx, FLAT_REORDER_CONTROL_END_X, FLAT_REORDER_CONTROL_STROKE_1_Y);
CGContextMoveToPoint(ctx, FLAT_REORDER_CONTROL_START_X, FLAT_REORDER_CONTROL_STROKE_2_Y);
CGContextAddLineToPoint(ctx, FLAT_REORDER_CONTROL_END_X, FLAT_REORDER_CONTROL_STROKE_2_Y);
CGContextMoveToPoint(ctx, FLAT_REORDER_CONTROL_START_X, FLAT_REORDER_CONTROL_STROKE_3_Y);
CGContextAddLineToPoint(ctx, FLAT_REORDER_CONTROL_END_X, FLAT_REORDER_CONTROL_STROKE_3_Y);
CGContextSetLineWidth(ctx, FLAT_REORDER_CONTROL_STROKE_WIDTH);
[self.accessoryColor setStroke];
CGContextStrokePath(ctx);
}