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.


    background color cannot be set for textfield

    Pythonista
    2
    6
    2545
    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.
    • peter
      peter last edited by

      Hi All,

      In my toy program, the root view contains a text field control which was added in the UI editor. The background color of the text field is always white regardless of the color setting in UI editor. I also tried to set the color by code and it had no effect on the UI. Any idea?

      Thanks.

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

        @peter put you TextField over an ui.View and play with its opacity, like here

        from objc_util import *
        import ui
        
        v = ui.View()
        v.frame = (0,0,200,50)
        
        tf_back = ui.View()
        tf_back.frame = (10,10,180,30)
        tf_back.background_color = 'blue'
        tf_back.corner_radius = 5
        v.add_subview(tf_back)
        
        tf = ui.TextField()
        tf.frame = (0,0,tf_back.width,tf_back.height)
        tf.alpha = 0.9
        tf_back.add_subview(tf)
        
        v.present('sheet')
        
        1 Reply Last reply Reply Quote 0
        • peter
          peter last edited by peter

          @cvp thank you for the quick response.

          Your method works but not ideal because the text also becomes transparent. Is this bug or intended behavior?

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

            @peter You are right, and I think it is the normal behavior.
            There should be an objectiveC solution...

            Edit: I have tried some ones but without success, up to now

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

              @peter Eureka (I had used this textField() one year ago and had already forgotten 😢)

              from objc_util import *
              import ui
              
              v = ui.View()
              v.frame = (0,0,200,50)
              
              tf = ui.TextField()
              tf.frame = (10,10,180,30)
              tf.tint_color = 'black'
              v.add_subview(tf)
              
              tfo = ObjCInstance(tf).textField()
              tfo.backgroundColor = ObjCClass('UIColor').colorWithRed_green_blue_alpha_(1, 0, 0, 1)
              
              v.present('sheet')
              
              1 Reply Last reply Reply Quote 1
              • peter
                peter last edited by

                Your objectiveC code worked wonderfully. Thank you again.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors