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.
Change DataPicker Textcolor.
-
Hi,
how to change the textcolor of a Datapicker. Temporaly it is only Black?
Thanks a lot.
Cu kami
-
import ui from objc_util import ObjCInstance,ObjCClass v = ui.View() v.background_color = 'white' dp = ui.DatePicker() objc = ObjCInstance(dp) back_ui_color = ObjCClass('UIColor').color(red=0.0, green=0.0, blue=1.0, alpha=1.0) objc.backgroundColor = back_ui_color text_ui_color = ObjCClass('UIColor').color(red=1.0, green=1.0, blue=1.0, alpha=1.0) objc.setValue_forKeyPath_(text_ui_color,"textColor") v.add_subview(dp) v.present()```
-
@cvp The background color can be set without
objc_util
as well. By default it is transparent, butdp.background_color = "blue"
works for example.The text color can only be set with
objc_util
. However you should be aware that this is not a public API - theUIDatePicker
documentation explicitly says "The appearance ofUIDatePicker
is not customizable."In general, if a property is not accessible through a normal getter/setter method, it's probably private and unsupported. You can often use tricks like
setValue:forKey:
or private methods (starting with an underscore) to read and write such properties anyway, but that may stop working in future iOS versions. -
@dgelessus Did not know about background. About the text color, I had read the same infos but some people use this objective c without problem...But I agree with you.
-
Hi,
thanks a lot. This works great.
BR
kami
-
Hi,
i am trying this part with my xcode template:
objc = ObjCInstance(v['datepicker1'])
text_ui_color = ObjCClass('UIColor').color(red=1.0, green=1.0, blue=1.0, alpha=1.0)
objc.setValue_forKeyPath_(text_ui_color,"textColor")
v.present('sheet', hide_title_bar=True)After compiling i get this error:
Traceback (most recent call last):
File "/var/mobile/Containers/Data/Application/5F678712-8E2D-4524-9835-0212BB429000/Library/Application Support/PythonistaScript/main.py", line 122, in <module>
text_ui_color = ObjCClass('UIColor').color(red=1.0, green=1.0, blue=1.0, alpha=1.0)
File "/var/containers/Bundle/Application/ABFA86F0-AD8F-46F5-A0EF-86A6B5FF5A02/sendpulse.app/Frameworks/PythonistaKit.framework/pylib/site-packages/objc_util.py", line 347, in getattr
cached_method = ObjCClassMethod(self, attr)
File "/var/containers/Bundle/Application/ABFA86F0-AD8F-46F5-A0EF-86A6B5FF5A02/sendpulse.app/Frameworks/PythonistaKit.framework/pylib/site-packages/objc_util.py", line 600, in init
raise AttributeError('No class method found for selector "%s"' % (self.sel_name))
AttributeError: No class method found for selector "color"if i use it directly with Pythonista everything works fine.
BR kami
-
@kami Sorry it I can't help, I don't know anything about Xcode...
-
Are you using objc_util.py from the template? Or from the most recent appstore version?
At some point, the syntax was changed to allow more pythonic calling, by detecting words like "with", etc. In older versions it would be something like
.colorWithRed_green_blue_alpha_(1,1,1,1)Or, you could do in this case
.whiteColor() -
Hi,
it is working really fine with .whiteColor().
Thanks a lot.
Cu kami