Change textColor, viewBackground & subview Background

守給你的承諾、 提交于 2021-01-29 09:50:21

问题


I want to change view controllers background color, subviews background color, & text color on condition.

For example:

There are 2 options (A & B ViewController) on mainViewcontroller.

  • 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.

  • 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.

I'm using this approach

 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)
    }
}

回答1:


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
    }
}


来源:https://stackoverflow.com/questions/59776362/change-textcolor-viewbackground-subview-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!