Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UITabBarItem theme_setTitleTextAttributes crash #147

Open
Auk513 opened this issue Mar 10, 2021 · 3 comments
Open

UITabBarItem theme_setTitleTextAttributes crash #147

Auk513 opened this issue Mar 10, 2021 · 3 comments

Comments

@Auk513
Copy link

Auk513 commented Mar 10, 2021

I want to set UITabBarItem titleTextAttributes from Plist. Copy the code from UINavigationBar.apperance() in the Plist Demo.

// tab bar item
        let tabBarItem = UITabBarItem.appearance()
        tabBarItem.theme_setTitleTextAttributes(ThemeStringAttributesPicker(keyPath: "Global.barTextColor") { value -> [NSAttributedString.Key : AnyObject]? in
            guard let rgba = value as? String else {
                return nil
            }

            let color = UIColor(rgba: rgba)
            let shadow = NSShadow(); shadow.shadowOffset = CGSize.zero
            let titleTextAttributes = [
                NSAttributedString.Key.foregroundColor: color,
                NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16),
                NSAttributedString.Key.shadow: shadow
            ]

            return titleTextAttributes
        }, forState: UIControl.State.normal)

Then it crash.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Have you sent -theme_setTitleTextAttributes:forState: to <UITabBarButtonLabel: 0x7fad8c407f00; frame = (0 0; 50.3333 12); text = 'PlistDemo'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600003f84c80>> off the main thread? To verify, look for a complaint in the logs: "Unsupported use of UIKit…", and fix the problem if you find it. If your use is main-thread only please file a radar on UIKit, and attach this log. exercisedImplementations = {
    "theme_setTitleTextAttributes:forState:" =     (
    );
}'
@aarashgoodarzi
Copy link

Same issue
I fixed this by observing theme and setting setTitleTextAttributes by my own

@wxxsw
Copy link
Owner

wxxsw commented Apr 17, 2021

I didn't find the real reason. I tested UITabBarItem.appearance().theme_setTitleTextAttributes(...) and it would crash, but UITabBarItem().theme_setTitleTextAttributes(...) would not crash. I guessed inside the object returned by UITabBarItem.appearance() There is some unknown logic blocking this. I don’t have a solution right now, and I will come back to this issue in the future.

@linlinyao1
Copy link

linlinyao1 commented Oct 27, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants