Chameleon+Ring.swift 3.26 KB
Newer Older
Thibault Wittemberg's avatar
Thibault Wittemberg committed
1
/*
2
 *  Copyright (C) 2017 Savoir-faire Linux Inc.
Thibault Wittemberg's avatar
Thibault Wittemberg committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
 *
 *  Author: Thibault Wittemberg <thibault.wittemberg@savoirfairelinux.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 */

import Foundation
import Chameleon

extension Chameleon {
    static func setRingThemeUsingPrimaryColor (_ primaryColor: UIColor, withSecondaryColor secondaryColor: UIColor, andContentStyle contentStyle: UIContentStyle) {

        var contentColor: UIColor
        var secondaryContentColor: UIColor

        switch contentStyle {
        case .contrast:
            contentColor = ContrastColorOf(primaryColor, returnFlat: false)
            secondaryContentColor = ContrastColorOf(secondaryColor, returnFlat: false)
        case .light:
            contentColor = UIColor.white
            secondaryContentColor = UIColor.white
        case .dark:
            contentColor = UIColor.flatBlackColorDark()
            secondaryContentColor = UIColor.flatBlackColorDark()
        }

        UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = UIColor.flatGray()

        MessageBubble.appearance().tintColor = secondaryContentColor
        MessageBubble.appearance().backgroundColor = secondaryColor

        MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellSent.self]).tintColor = contentColor
48 49
        MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellSent.self]).backgroundColor = UIColor.ringMsgCellSent
        UILabel.appearance(whenContainedInInstancesOf: [MessageBubble.self, MessageCellSent.self]).textColor = UIColor.ringMsgCellSentText
Thibault Wittemberg's avatar
Thibault Wittemberg committed
50 51

        MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellReceived.self]).tintColor = secondaryContentColor
52 53
        MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellReceived.self]).backgroundColor = UIColor.ringMsgCellReceived
        UILabel.appearance(whenContainedInInstancesOf: [MessageBubble.self, MessageCellReceived.self]).textColor = UIColor.ringMsgCellReceivedText
54 55 56

        MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellGenerated.self]).tintColor = UIColor.clear
        MessageBubble.appearance(whenContainedInInstancesOf: [MessageCellGenerated.self]).backgroundColor = UIColor.clear
57 58 59 60 61 62

        UIButton.appearance().backgroundColor = UIColor.clear
        DesignableButton.appearance().backgroundColor = secondaryColor
        ButtonTransparentBackground.appearance().tintColor = secondaryColor
        ButtonTransparentBackground.appearance().backgroundColor = UIColor.clear
        UIButton.appearance(whenContainedInInstancesOf: [UIView.self, UIImagePickerController.self]).tintColor = UIColor.white
Thibault Wittemberg's avatar
Thibault Wittemberg committed
63 64
    }
}