0
0

More than 1 year has passed since last update.

UITableViewCellの.disclosureIndicatorのアクセサリタイプの色適用

Last updated at Posted at 2022-07-26

概要

  • 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

表示確認

色適用後 標準表示
2022-07-26 19.57のイメージ.jpg スクリーンショット 2022-07-26 20.11.28.png

その他

  • accessoryType = .checkmark の場合は、cell.tintColorで色適用可能
  • システム画像はSF Symbolsをダウンロードすればシステム画像が見れる
    スクリーンショット 2022-07-26 19.48.59.png

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0