Is it possible to force alignment of the title of an ui.Button?
I build a TableView grid where each cell is a ui.Button. Some columns are amounts, thus I want to right align these amounts in their column. Hoping I'm clear enough in my poor English.
I don't think so. Just poked into a buttons subviews and there is no Label to mess with. But I might be wrong as I mostly do ignore the
uistuff. Cheap workaround: Calculate the the maximum length of your buttons title strings and do It by hand using
str.center(), using your calculated maximum length.
I also had a look. I suspect the button has a subview of ui.Label but I don't think you can access it in the Pythonista API. I am just guessing, but that's what it looks like to me.
@zipit thanks to (try to) help me but it's not so easy. My font has not a fixed size for all characters.
I've already scanned all elements of each column to compute the width of the column but each cell is a button. I know I could have a label as subview of the button but I think it's additional load...
@Phuket2 Thanks also to (try to) help me... I know also that but I had found (Google of course) other guys with same problem, even with Objective-c or Swift.
@cvp , np. But you could also just write your own custom class to emulate a btn class. Override the draw method to draw the button using ui.Path methods and use the touch_x methods to handle the click etc. it will not be slow
@Phuket2 A little bit too complex for me 😞
@cvp , pretty sure zipit is writing it now :)
You could use a Label instead of a Button (with a text-free button behind it)
If you need button, you can use objc
where alignment can be 0, 1,or 2 for center, left, right respectively.
@JonB Whaaaaa. I had found this attribute but I was not able to use it. I had tried ObjcInstance(b).contentHorizontalAlignment but without this ".button"...
I try it immediately and give a feedback
Thanks a lot for the help
Of course, it's ok 🍾
This is more elegant than all other methods
@JonB Why this ".button"?