更改单元格select的公开指示符颜色
我已经阅读了一些这方面的post,但仍然无法得到我的问题的答案。
我有一个披露指标。
我像这样添加它:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
一切工作正常,是好的,唯一我想改变的是,当我按下单元格,披露指标变为白色的颜色。 我不要那个。 所以我的问题是如何使披露指标的颜色固定,而不是改变?
您需要为此使用自定义附件视图。 句法:
cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"accessory.png"]] autorelease];
在这里,你正在分配一个图像视图与图像accessory.png
到你的电池的附件视图。
Swift 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
你可以尝试使用uiimageview来应用像下面的代码cellType:
cell.accessoryView = myAccessoryUIImageView;
cell accessoryview uiimageview不正确alignment请尝试以下代码:
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!
尝试这样的事情。 大概你可以达到你想要的。
-(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; } } } } }
我面临同样的问题,发现即使你正在努力…虽然它的相当晚的答案,但我整理了我的问题写下面的行,
cell.selectionStyle = UITableViewCellSelectionStyleNone;
它停止附件typesUITableViewCellAccessoryDisclosureIndicator被选为白色。
希望这有助于。
Swift 3 – 一个简单的Table View类,可以在configuration单元格时使用showsDisclosure
布尔值来显示泄漏指示符。 现在公开的箭头色调是硬编码的,但是如果你想要一个更可重用的单元格,你的颜色select可以很容易地通过configuration函数传入。
请注意,“雪佛龙”图像被设置为资产目录中的模板图像,这意味着它可以着色一种颜色。 你也可以像这样在代码中将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 appearance] setTintColor:[UIColor redColor]];