Mohammed Saleh
Mohammed Saleh

Reputation: 77

How to allow user to customize application theme color, text font and text font size in runtime like Telegram application?

My application has a setting screen that allows the user to change app color including navigation bar and tab bar tint colors and also allow him to change app font and font size for all texts in the app like in Telegram application. the problem is when user select a color for a list of specific colors I need something like reloads or refreshes my application to make the change affect the tab bar and navbar of the application

I found this question but it changes the color one time when the app launched but I want to allow the user to customize the application color and font

Changing navigation bar color in Swift

Upvotes: 0

Views: 129

Answers (1)

Mohammed Saleh
Mohammed Saleh

Reputation: 77

After a long search, I found the answer to fix the problem of the change navigation bar and tab bar color, tint color, and font in run time when the user chooses a specific color.

to change the color of the navigation bar: use this to change the color of navbar for the current screen

navigationController?.navigationBar.barTintColor = Color

and that for changing the color for navbar in the entire app

UINavigationBar.appearance().tintColor = Color
UINavigationBar.appearance().barTintColor = Color

and this for changing navbar font for the current screen

navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: AppFont().large]

and this for the entire app

UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white, NSAttributedString.Key.font: AppFont().large]

and this for change tab bar tint color

self.tabBarController?.tabBar.tintColor = Color.theme.value

and this to change tab bar items font

let selectedAttrs = [NSAttributedString.Key.font: Font, NSAttributedString.Key.foregroundColor: Color]

    if let items = self.tabBarController?.tabBar.items {
        for item in items {
            item.setTitleTextAttributes(selectedAttrs, for: .selected)
        }
    }

https://gph.is/g/ZOR7bAP

Upvotes: -1

Related Questions