我正在使用MSCellAccessory为accessoryView设置自定义颜色。它工作正常。但是当我在单元格中放置按钮并单击单元格时,复选标记可见,但它与删除按钮重叠。检查我的快照。
那么如何在UITableViewCell中更改cell accessoryView位置或在delete button下面设置accessoryView。
答案 0 :(得分:0)
If you are sub-classing the UITableViewCell you can adjust it in layoutSubviews
- (void)layoutSubviews {
[super layoutSubviews];
CGRect accessoryViewFrame = self.accessoryView.frame;
accessoryViewFrame.origin.x = CGRectGetWidth(self.bounds) - CGRectGetWidth(accessoryViewFrame);
self.accessoryView.frame = accessoryViewFrame;
}
OTHERWISE......
Add subview instead of accessoryView
UIButton *indicatorBtn = [UIButton buttonWithType:UIButtonTypeCustom];
indicatorBtn.frame = CGRectMake(cell.contentView.frame.size.width-55, 2, 50, 50);
[indicatorBtn setBackgroundImage:[UIImage imageNamed:@"right_indicator.png"]
forState:UIControlStateNormal];
indicatorBtn.backgroundColor = [UIColor clearColor];
//indicatorBtn.alpha = 0.5;
indicatorBtn.tag = indexPath.row;
[indicatorBtnaddTarget:self action:@selector(method:)
forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:indicatorBtn];
答案 1 :(得分:-1)
我通过添加UIImageView来解决问题。并放在删除按钮旁边,它适用于我。我没有使用台式电池配件。请查看以下代码。
- (UITableViewCell *)reuseTableViewCellWithIdentifier:(NSString *)identifier
{
CGRect cellRectangle = CGRectMake(0, 0, CGRectGetWidth(tableViewSavedSearch.frame), tableViewSavedSearch.rowHeight);
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.frame = cellRectangle;
CGFloat imageWidth = 30;
//Name
UILabel *lblName = [DesignModel createPaddingLabel:CGRectMake(0, 0, CGRectGetWidth(cellRectangle) - (imageWidth * 2), tableViewSavedSearch.rowHeight) labelTag:TAG_SAVED_SEARCH_NAME textColor:COLOUR_BLUE_DARK textAlignment:NSTextAlignmentLeft textFont:[UIFont fontWithName:FONT_CENTURY_GOTHIC size:14] padding:UIEdgeInsetsMake(0, 5, 0, 5)];
[cell.contentView addSubview:lblName];
//Delete button
UIButton *button = [DesignModel createImageButton:CGRectMake(CGRectGetMaxX(lblName.frame), 0, imageWidth, tableViewSavedSearch.rowHeight) image:imageDelete tag:TAG_SAVED_SEARCH_DALETE];
[button addTarget:self action:@selector(btnSaveAndSearch_DeleteAction:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button];
//TICK
UIImageView *imageView = [DesignModel createImageView:CGRectMake(CGRectGetMaxX(button.frame), 0, imageWidth, tableViewSavedSearch.rowHeight) image:imageTick tag:TAG_SAVED_SEARCH_TICK contentMode:UIViewContentModeCenter];
[cell.contentView addSubview:imageView];
return cell;
}