概要
- UITableViewCellで.disclosureIndicatorのアクセサリタイプを表示する際に色適用をする
- 通常のcell.tintColor設定では色適用されない※iOS13以前はできたかも
.disclosureIndicatorの色適用
このやり方がiOS標準で表示されるものと一番近い
let chevronColor = UIColor.red
// システムイメージの表示設定を行う,iOS13以後サポート
let chevronConfig = UIImage.SymbolConfiguration(pointSize: 14, weight: .regular)
guard let chevronImg = UIImage(systemName: "chevron.right", withConfiguration: chevronConfig)?.withTintColor(chevronColor, renderingMode: .alwaysTemplate) else { return }
let chevron = UIImageView(image: chevronImg)
chevron.tintColor = chevronColor
let customDisclosureIndicator = UIView(frame: CGRect(x: 0, y: 0, width: 15, height: frame.height))
customDisclosureIndicator.addSubview(chevron)
// AutoLayoutでレイアウト構築しない
chevron.translatesAutoresizingMaskIntoConstraints = false
// 「>」ビューの右端と親ビューの右端に揃える
chevron.trailingAnchor.constraint(equalTo: customDisclosureIndicator.trailingAnchor,constant: 0).isActive = true
// 「>」ビューの縦方向中心は親ビューの縦方向の中心と同様
chevron.centerYAnchor.constraint(equalTo: customDisclosureIndicator.centerYAnchor).isActive = true
self.accessoryView = customDisclosureIndicator
表示確認
色適用後 | 標準表示 |
---|---|
![]() |
![]() |
その他
- accessoryType = .checkmark の場合は、cell.tintColorで色適用可能
- システム画像はSF Symbolsをダウンロードすればシステム画像が見れる
参考