Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Tint Color of segmented Control doesn't work
-
Hallo,
The Tint Color of segmented Control doesn't work.
This is only on my iPad Pro (10.5). My old iPad Air doesn't have these problem.I have the Problem using a pyui file OR using a class (ui.view, using a py file) with something like that:
Btw.: the button works correct.
import ui class cUIViewMain(ui.View): def __init__(self): self.background_color = 'lightgrey' self.width = 250 self.height = 100 self.btn01 = self.makeButtons('btn01') vSeg01 = ('A1', 'A2', 'A3', 'A4') self.seg01 = self.makeSegmentedControl(vSeg01) self.style() def layout(self): self.btn01.frame = (10, 5, 80, 40) self.seg01.frame = (10, 50, 200, 40) def style(self): self.btn01.tint_color = 'yellow' self.seg01.tint_color = 'yellow' #funktioniert nicht (https://forum.omz-software.com/topic/4652/tint-color-can-t-be-set/6) def makeButtons(self, vName): button = ui.Button() button.title = vName button.border_width = 1 self.add_subview(button) return button def makeSegmentedControl(self, vSegments): vSegmentedControl = ui.SegmentedControl() vSegmentedControl.segments = vSegments self.add_subview(vSegmentedControl) return vSegmentedControl if __name__ == '__main__': vView = cUIViewMain() vView.present('sheet')
I know there is a thread, but this is not the same.
https://forum.omz-software.com/topic/4652/tint-color-can-t-be-set -
@7upser have you tried setting the color value inside custom attributes in the ui builder for the pyui?
-
Yes, i try it with a dummy pyui.
It is alway black and white.
(and i thought it should be blue and white)
(i dont know, how to upload, but this should also work :) ) -
@7upser to show imag just use this

what did u put inside the custom attribute section on builder for the segment control
-
Thanks,
I make a new pyui, added a segmented control.
And then only change Size and Tint Color. Rest is default.
For Tint Color i only one tap on the color menu. -
@7upser on my iPad Air2 tjis is the same give me few min to run som tests and ill be right back
-
Take your time, this isn't the most important thing, especially not now
-
@7upser try this
from objc_util import * . . . def style(self): self.btn01.tint_color = 'yellow' #self.seg01.tint_color = 'yellow' #funktioniert nicht (https://forum.omz-software.com/topic/4652/tint-color-can-t-be-set/6) vo = ObjCInstance(self.seg01).segmentedControl() yellow = UIColor.yellowColor() UIFont = ObjCClass('UIFont').fontWithName_size_('Menlo',15) attributes = {'NSFont': UIFont, 'NSColor': yellow} vo.setTitleTextAttributes_forState_(attributes, 0)
-
Yeah, great.
Thanks but it sounds like a bug.And glad to see, that my bad english doesn't matter
Stay health, both
-
-
-
@7upser even in Objectivec, tint color is not ok
yellow = UIColor.yellowColor() vo.setTintColor_(yellow)
Edit: seen your previous post after writing this one
-
we might need to look into out
objc_util
module this might be the third ocurance that ive see that Apple changed API and renders our use incapable. i tried all i could and i get the same error stating the method doesnt exist.. but i did see that there might be a work around to use old ios12 styling only mjor featur that i saw that you lose is darkmode. you will only get the light mode ]. below is what i sawvabout this. its from @7upser 's link i believe its refering to swift code im not sure... but its the best i could findTo get back iOS 12 appearance
I wasn't able to tint the color of the selected segment, hopefully it will be fixed in an upcoming beta.
Setting the background image of the selected state doesn't work without setting the background image of the normal state (which removes all the iOS 13 styling)
But I was able to get it back to the iOS 12 appearance (or near enough, I wasn't able to return the corner radius to its smaller size).
It's not ideal, but a bright white segmented control looks a bit out of place in our app.
(Didn't realise UIImage(color:) was an extension method in our codebase. But the code to implement it is around the web)extension UISegmentedControl { /// Tint color doesn't have any effect on iOS 13. func ensureiOS12Style() { if #available(iOS 13, *) { let tintColorImage = UIImage(color: tintColor) // Must set the background image for normal to something (even clear) else the rest won't work setBackgroundImage(UIImage(color: backgroundColor ?? .clear), for: .normal, barMetrics: .default) setBackgroundImage(tintColorImage, for: .selected, barMetrics: .default) setBackgroundImage(UIImage(color: tintColor.withAlphaComponent(0.2)), for: .highlighted, barMetrics: .default) setBackgroundImage(tintColorImage, for: [.highlighted, .selected], barMetrics: .default) setTitleTextAttributes([.foregroundColor: tintColor, NSAttributedString.Key.font: UIFont.systemFont(ofSize: 13, weight: .regular)], for: .normal) setDividerImage(tintColorImage, forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default) layer.borderWidth = 1 layer.borderColor = tintColor.cgColor } } }