更改 textColor、viewBackground &子视图背景 [英] Change textColor, viewBackground & subview Background
问题描述
我想更改视图控制器背景颜色、子视图背景颜色,&文字颜色视情况而定.
I want to change view controllers background color, subviews background color, & text color on condition.
例如:
mainViewcontroller 上有 2 个选项(A & B ViewController).
There are 2 options (A & B ViewController) on mainViewcontroller.
如果用户选择 A ViewController,那么它会按照它的颜色从 A 到 X、Y、Z ViewsControllers,直到我推送、performSegue 或呈现 X、Y、Z 视图控制器.
If a user chooses A ViewController then it will follow its color from A to X, Y, Z ViewsControllers till I push, performSegue, or present X, Y, Z View Controllers.
如果用户选择 B ViewController,那么它会跟随它的颜色从 B 到 X、Y、Z ViewsControllers,直到我推送、performSegue 或呈现 X、Y、Z 视图控制器.
If a user chooses B ViewController then it will follow its color from B to X, Y, Z ViewsControllers till I push, performSegue or present X, Y, Z View Controllers.
注意:这些子视图可以包括表视图、集合视图、集合视图中的表视图或表视图中的集合视图提前致谢.
Note: Those subviews could include tableview, collectionview, tableView in CollectionView Or CollectionView in tableView Thanks in advance.
我正在使用这种方法
if gold {
if let vc = storyboard?.instantiateViewController(withIdentifier: "ListView") as? ListView {
vc.gold = true
vc.mainBackgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
vc.labelColor = #colorLiteral(red: 0.968627451, green: 0.6196078431, blue: 0.1529411765, alpha: 1)
vc.topBarColor = #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)
present(vc, animated: true, completion: nil)
}
}
推荐答案
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
self.performSegue(withIdentifier: "ThisColorSegue", sender: nil)
} else if indexPath.row == 1 {
self.performSegue(withIdentifier: "ThatColorSegue", sender: nil)
} else if indexPath.row == 2 {
self.performSegue(withIdentifier: "SomeOtherColorSegue", sender: nil)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ThisColorSegue", let dest = segue.destination as? ZController {
dest.color = SomeColor
}
}
这篇关于更改 textColor、viewBackground &子视图背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!