简体   繁体   English

UITableViewCell附件视图重叠单元格的自定义按钮或如何更改附件视图位置?

[英]UITableViewCell accessoryView overlap custom button of cell OR how to change accessoryView position?

I am using MSCellAccessory to set custom colour to accessoryView.我正在使用MSCellAccessory将自定义颜色设置为附件视图 It worked fine.它工作得很好。 But when I place button in cell and click on cell, checkmark is visible but it overlaps delete button.但是当我在单元格中放置按钮并单击单元格时,复选标记是可见的,但它与删除按钮重叠。 Check my snap shot.检查我的快照。 在这张图片中,我将边框设置为附件视图。它出现在删除。所以我不能按删除按钮。

So how to change cell accessoryView position in UITableViewCell or set accessoryView below delete button.那么如何更改 UITableViewCell 中的单元格附件视图位置或在删除按钮下方设置附件视图。

If you are sub-classing the UITableViewCell you can adjust it in layoutSubviews如果您对 UITableViewCell 进行子类化,则可以在 layoutSubviews 中对其进行调整

- (void)layoutSubviews {
    [super layoutSubviews];

    CGRect accessoryViewFrame = self.accessoryView.frame;
    accessoryViewFrame.origin.x = CGRectGetWidth(self.bounds) - CGRectGetWidth(accessoryViewFrame);
    self.accessoryView.frame = accessoryViewFrame;
}

OTHERWISE......除此以外......
Add a 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;
[indicatorBtn addTarget:self action:@selector(method:) 
       forControlEvents:UIControlEventTouchUpInside];

[cell.contentView addSubview:indicatorBtn];

I solved by adding UIImageView for tick.我通过添加 UIImageView 来解决。 And put beside the delete button, and it works for me.放在删除按钮旁边,它对我有用。 I am not using table cell accessory.我没有使用桌面单元配件。 Please check below code.请检查以下代码。

- (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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM