改变UIColorPickerViewController的文本颜色?

huangapple go评论79阅读模式
英文:

Change text color of UIColorPickerViewController?

问题

I do not see any way to change the text color for a UIColorPickerViewController. Otherwise it's perfect for my needs and would prefer to use it versus making my own picker. I have a light and dark theme for my app and is important that I match the theme.

I've tried the usual hacks like:

myPickerView.setValue(UIColor.red, forKey: "textColor")

But it's not key textColor compliant and crashes.

Changing the tint color changes the eyedropper icon but no text:

myPickerView.view.tintColor = .cyan

The toolbarItems property is nil.

I tried overriding preferredStatusBarStyle:

class MyUIColorPickerViewController: UIColorPickerViewController {   
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .darkContent
    }
}

It has a navigationItem property, but all of its' properties are nil and navigationController is nil.

I tried looking at all the subviews of its subviews, but nothing. Seems like there must be a way. Sad Apple doesn't provide us very basic control over its appearance.

英文:

I do not see any way to change the text color for a UIColorPickerViewController. Otherwise it's perfect for my needs and would prefer to use it versus making my own picker. I have a light and dark theme for my app and is important that I match the theme.

I've tried the usual hacks like:

myPickerView.setValue(UIColor.red, forKey: "textColor")

But it's not key textColor compliant and crashes.

Changing the tint color changes the eyedropper icon but no text:

myPickerView.view.tintColor = .cyan

The toolbarItems property is nil.

I tried overriding preferredStatusBarStyle:

class MyUIColorPickerViewController:UIColorPickerViewController {   
    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .darkContent
    }
}

It has a navigationItem property, but all of its' properties are nil and navigationController is nil.

I tried looking at all the subviews of its subviews, but nothing. Seems like there must be a way. Sad Apple doesn't provide us very basic control over its appearance.

答案1

得分: 1

如果只是为了匹配您自定义的深色和浅色主题,您可以将overrideUserInterfaceStyle设置为与.light/.dark值匹配的颜色选择器视图控制器。

// 当您处于自己的深色模式时
myPickerView.overrideUserInterfaceStyle = .dark
英文:

If it is just to match your own custom dark and light themes, you can set overrideUserInterfaceStyle on the color picker view controller to the matching .light/.dark value.

// when in your own dark mode
myPickerView.overrideUserInterfaceStyle = .dark

huangapple
  • 本文由 发表于 2023年6月12日 14:46:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454166.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定