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.
How to prevent button flickering on title change?
-
Whenever I update the title of a ui.button an animation is shown (so it appears as if the button flickers).
This seems to be normal on iOS, and this is how it can be prevented in native Apps: https://stackoverflow.com/questions/18946490/how-to-stop-unwanted-uibutton-animation-on-title-change
Is there a way to prevent this animation in Pythonista (for example using obj_c )?
I would really like to use a button and not a custom view...
-
@FrankenApps same here
-
@FrankenApps this has worked but no more today, don’t know why
import ui from objc_util import * UIButton = ObjCClass('UIButton') class my: def __init__(self): pass def handler(self,_cmd,obj1_ptr): print('handler',self.title) self.UIButton.title = self.title def setTitleWithoutAnimation(self,ui_button, title): o = ObjCInstance(ui_button) self.UIButton = False for subview in o.subviews(): if subview.isKindOfClass(UIButton): self.UIButton = subview break if not self.UIButton: return self.title = title block = ObjCBlock(self.handler, restype=None, argtypes=[c_void_p, c_void_p]) # class/type method, not instance method UIButton.animateWithDuration_animations_(0,block) m=my() v = ui.View() v.frame =(0,0,100,100) b = ui.Button() b.frame = (10,10,80,32) b.title = 'tap' def b_action(sender): m.setTitleWithoutAnimation(sender,'done') b.action = b_action v.add_subview(b) v.present('sheet')
-
@cvp Thanks, I‘ll Play around with this a bit. I have Not seen that other thread, so sorry for the duplicate..
-
@FrankenApps no problem, often not easy to search in forum, better to search via google 😃