お世話になります。
UILabelの部分をタップするとホワイトになり、離すとブラックになる様に
isHighlightedを実装したいのですが、
タップするとその状態(ホワイト)のままになり、ブラックに戻らず困っています。
title0.tintColor = だと無反応だったので
title0.textColor = にしたのですが、うまく実装できません。
これ以外の定義で白黒切り替えることは可能でしょうか?
class HogeCell: UICollectionViewCell {
//省略してます...
let hogeLabel: UILabel = { let label = UILabel() label.text = "こんにちは" label.font = UIFont.systemFont(ofSize: 38) label.isHighlighted = true //label.highlightedTextColor = UIColor.white label.translatesAutoresizingMaskIntoConstraints = false return label }() override var isHighlighted: Bool { didSet { title0.textColor = isHighlighted ? UIColor.white : UIColor.black print("タップ") } } override var isSelected: Bool { didSet { title0.textColor = isHighlighted ? UIColor.white : UIColor.black print("タップ") } }
また、タップできるUILabelは2つあり、 RUN後に0番目のUILabelがタップ済み(ホワイト)の状態で現れる様にNSIndexPath(item: 0, section: 0)を定義したつもりですが、 こちらもRUN後あらかじめホワイトになっているUILabelはありません。 ```ここに言語を入力 class HugaView: UIView, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout { override init(frame: CGRect) { super.init(frame: frame) collectiomView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cellId") // let selectedIndexPath = NSIndexPath(item: 0, section: 0) collectiomView.selectItem(at: selectedIndexPath as IndexPath, animated: false, scrollPosition: []) backgroundColor = .yellow???? } //省略してます...
調べてはいるのですが、分からないため質問いたします。
教えて頂ければ幸いです。
回答1件
あなたの回答
tips
プレビュー