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.


    CoreAnimation / CAGradientLayer

    Pythonista
    framework objcutil animation objc
    3
    6
    3921
    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.
    • reticulated
      reticulated last edited by

      Hello Pythonistas,

      I need some help - how can I use objc_util to use the CAGradientLayer class.

      I can't seem to figure out what Framework(s) I might need to load.

      Using ObjcClass it can't seem to find CAGradientLayer.

      Ideally I want to setup a function which can generate buttons and views with a gradient as a background.

      Any help would be appreciated!

      mikael cvp 3 Replies Last reply Reply Quote 0
      • mikael
        mikael @reticulated last edited by mikael

        @reticulated, looks like it is in the QuartzCore framework.

        NSBundle.bundle(Path="/System/Library/Frameworks/QuartzCore.framework").load()
        

        Would be interesting to see your results.

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

          @reticulated I don't think we need something more than objectivec, see here for something similar.
          But I've tried the same process without success, until now

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

            @reticulated @mikael

            Eureka (my error, colors need to be CGColors...)

            from objc_util import *
            import ui
            
            v = ui.View()
            v.frame = (0,0,300,300)
            ov = ObjCInstance(v)
            layer=ov.layer()
             
            CAGradientLayer = ObjCClass('CAGradientLayer')
            grlayer = CAGradientLayer.layer()
            grlayer.frame=layer.bounds()
            
            grlayer.setColors_([ObjCClass('UIColor').blueColor().CGColor(),ObjCClass('UIColor').redColor().CGColor()])
            
            layer.addSublayer_(grlayer)
            
            v.present('sheet')
            
            1 Reply Last reply Reply Quote 0
            • cvp
              cvp last edited by

              If you prefer to be able to set r,g,b colors:

              grlayer.setColors_([ObjCClass('UIColor').colorWithRed_green_blue_alpha_(1,0,0,1.0).CGColor(),ObjCClass('UIColor').colorWithRed_green_blue_alpha_(0.3,0,0,1.0).CGColor()])
              
              1 Reply Last reply Reply Quote 0
              • reticulated
                reticulated last edited by

                Hey thank you everyone.

                I must have had a typo when I initially posted this - but it seems to work now.

                Notes: I used ui.parse_color('blue').CGColor()

                This works with RGBA, Hex and Named Colors.

                Ill post the code when done, I am using this to create custom button styles, along with some custom styles for "checkbox" functionality (circles, squares, stars, etc)

                Thanks again for your help!

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