調べたところ、UIButtonのようなプロパティがないことがわかりました。
以下のように実装して解決しました。
Swift
1var filter = 0
2
3// フィルター項目3つにそれぞれ0~2を割り振って判定しています
4
5~~~~~~~~~~~~~~~~~~~~~~~~~~~
6switch self.filter {
7 case 0:
8 filterBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "line.horizontal.3.decrease.circle"), style: .plain, target: self, action: #selector(self.filterBarButtonTapped(_:)))
9 settingBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "gearshape"), style: .plain, target: self, action: #selector(self.settingBarButtonTapped(_:)))
10 self.navigationItem.leftBarButtonItems = [settingBarButtonItem, filterBarButtonItem]
11
12 case 1:
13 filterBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "line.horizontal.3.decrease.circle.fill"), style: .plain, target: self, action: #selector(self.filterBarButtonTapped(_:)))
14 settingBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "gearshape"), style: .plain, target: self, action: #selector(self.settingBarButtonTapped(_:)))
15 self.navigationItem.leftBarButtonItems = [settingBarButtonItem, filterBarButtonItem]
16
17 case 2:
18 filterBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "line.horizontal.3.decrease.circle.fill"), style: .plain, target: self, action: #selector(self.filterBarButtonTapped(_:)))
19 settingBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "gearshape"), style: .plain, target: self, action: #selector(self.settingBarButtonTapped(_:)))
20 self.navigationItem.leftBarButtonItems = [settingBarButtonItem, filterBarButtonItem]
21
22 default:
23 filterBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "line.horizontal.3.decrease.circle"), style: .plain, target: self, action: #selector(self.filterBarButtonTapped(_:)))
24 settingBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "gearshape"), style: .plain, target: self, action: #selector(self.settingBarButtonTapped(_:)))
25 self.navigationItem.leftBarButtonItems = [settingBarButtonItem, filterBarButtonItem]
26 }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。