omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    bug tint color
    3
    13
    6175
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • stephen
      stephen @7upser last edited by

      @7upser have you tried setting the color value inside custom attributes in the ui builder for the pyui?

      1 Reply Last reply Reply Quote 0
      • 7upser
        7upser last edited by ccc

        Yes, i try it with a dummy pyui.
        It is alway black and white.
        (and i thought it should be blue and white)
        image
        (i dont know, how to upload, but this should also work :) )

        1 Reply Last reply Reply Quote 0
        • stephen
          stephen @7upser last edited by

          @7upser to show imag just use this

          ![tag](url)
          

          what did u put inside the custom attribute section on builder for the segment control

          1 Reply Last reply Reply Quote 0
          • 7upser
            7upser last edited by

            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.

            stephen 1 Reply Last reply Reply Quote 0
            • stephen
              stephen @7upser last edited by

              @7upser on my iPad Air2 tjis is the same give me few min to run som tests and ill be right back

              1 Reply Last reply Reply Quote 0
              • 7upser
                7upser last edited by

                Take your time, this isn't the most important thing, especially not now

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @7upser last edited by cvp

                  @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)
                  
                  1 Reply Last reply Reply Quote 0
                  • 7upser
                    7upser last edited by 7upser

                    Yeah, great.
                    Thanks but it sounds like a bug.

                    And glad to see, that my bad english doesn't matter

                    Stay health, both

                    cvp 2 Replies Last reply Reply Quote 0
                    • cvp
                      cvp @7upser last edited by cvp

                      @7upser said:

                      my bad english doesn't matter

                      Your English is as good as mine

                      1 Reply Last reply Reply Quote 0
                      • 7upser
                        7upser last edited by

                        No :)

                        But with your solution i have something to google and found this:

                        iOS 13 changes

                        1 Reply Last reply Reply Quote 1
                        • cvp
                          cvp @7upser last edited by cvp

                          @7upser even in Objectivec, tint color is not ok

                                  yellow = UIColor.yellowColor()
                                  vo.setTintColor_(yellow) 
                          

                          Edit: seen your previous post after writing this one

                          stephen 1 Reply Last reply Reply Quote 1
                          • stephen
                            stephen @cvp last edited by stephen

                            @cvp @7upser

                            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 find

                            To 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
                                    }
                                }
                            }
                            
                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            Powered by NodeBB Forums | Contributors