我已经阅读了一些关于此的帖子,但仍然无法得到我的问题的答案。
我有一个披露指标。
我这样添加:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
一切正常,很好,我唯一想改变的是当我按下单元格时,披露指示器将颜色变为白色。我不想要那个。所以我的问题是如何使披露指示器颜色固定而不改变?
我已经阅读了一些关于此的帖子,但仍然无法得到我的问题的答案。
我有一个披露指标。
我这样添加:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
一切正常,很好,我唯一想改变的是当我按下单元格时,披露指示器将颜色变为白色。我不想要那个。所以我的问题是如何使披露指示器颜色固定而不改变?
您需要为此使用自定义附件视图。句法:
cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"accessory.png"]] autorelease];
在这里,您正在分配带有图像附件.png 的图像视图
到您的单元格的附件视图。
斯威夫特 3
添加自定义附件视图:
示例 1:
cell.accessoryView = UIImageView(image: UIImage(named: "accessory.png"))
示例 2:
嵌套在一个小源图像的视图容器中:
let accessoryView = UIView(frame: CGRect(x: 0, y: 0, width: 24, height: 50))
let accessoryViewImage = UIImageView(image: UIImage(named: "accessory.png"))
accessoryViewImage.center = CGPoint(x: 12, y: 25)
accessoryView.addSubview(accessoryViewImage)
cell.accessoryView = accessoryView
尝试这样的事情。也许你将能够实现你想要的。
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
for (id obj in cell.subviews){
if([obj isKindOfClass:[UIButton class]]) {
UIButton *button = obj;
for(id btnObj in button.subviews){
if([btnObj isKindOfClass:[UIImageView class]]) {
UIImageView *imgView = btnObj;
UIImage *image = [imgView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
imgView.image = image;
imgView.tintColor = cell.backgroundColor;
}
}
}
}
}
您可以尝试使用 uiimageview 来应用单元格附件类型,如下面的代码:
cell.accessoryView = myAccessoryUIImageView;
单元格附件视图 uiimageview 未正确对齐尝试以下代码:
UIView* accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 24, 50)];
UIImageView* accessoryViewImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"accessory_image.png"]];
accessoryViewImage.center = CGPointMake(12, 25);
[accessoryView addSubview:accessoryViewImage];
[cell setAccessoryView:accessoryView];
[accessoryViewImage release];//not use this line your ios sdk in 5.0 and above!
[accessoryView release];//not use this line your ios sdk in 5.0 and above!
我遇到了同样的问题,发现即使你也在为此苦苦挣扎......虽然它的答案很晚,但我通过写下一行来解决我的问题,
cell.selectionStyle = UITableViewCellSelectionStyleNone;
它在选择时停止了配件类型 UITableViewCellAccessoryDisclosureIndicator 为白色。
希望这有帮助。
斯威夫特版本:
cell.selectionStyle = .none
Swift 3 - 一个简单的表格视图类,可以showsDisclosure
在配置单元格时显示披露指示器或不使用布尔值。现在公开箭头的色调颜色是硬编码的,但是如果您想要一个更可重用的单元格,您的颜色选择也可以很容易地通过配置函数传递。
请注意,“chevron”图像设置为资产目录中的模板图像,这意味着它可以着色。您也可以在代码中将 UIImage 制作成模板图像,如下所示:UIImage(named: "chevron")?.withRenderingMode(.alwaysTemplate)
class HeaderTableViewCell: UITableViewCell {
@IBOutlet weak var sectionTitle: UILabel!
override func awakeFromNib() {
sectionTitle.textColor = .black
}
func configure(title: String, showsDisclosure: Bool = false) {
self.sectionTitle.text = title
if showDisclosure {
//add custom disclosure arrow
let chevronImgView = UIImageView(image: UIImage(named: "chevron"))
chevronImgView.tintColor = .red
self.accessoryType = .disclosureIndicator
self.accessoryView = chevronImgView
} else {
self.accessoryType = .none
self.accessoryView = nil
}
}
}
[[UITableViewCell 外观] setTintColor:[UIColor redColor]];