简体   繁体   中英

Change textColor, viewBackground & subview Background

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM