[AC-4787] iOS Button textAlign is wrong way round
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | n/a |
| Status | Resolved |
| Resolution | Not Our Bug |
| Resolution Date | 2017-02-12T17:26:59.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Titanium SDK & CLI |
| Labels | ios |
| Reporter | Lawrence Wilson |
| Assignee | Shak Hossain |
| Created | 2017-02-12T12:27:01.000+0000 |
| Updated | 2017-02-13T08:21:59.000+0000 |
Description
The textAlign property for a button on iOS seems to behave the wrong way around:
var button = Ti.UI.createButton({
width: Ti.UI.SIZE
, height: '30dp'
, text: 'Update status'
, textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT // or 'left'
, backgroundColor: '#DCB5FF'
});
Causes image attached. If the textAlign is set to right, then it justifies to left
Attachments
| File | Date | Size |
|---|---|---|
| Button_LEFT.png | 2017-02-13T08:21:48.000+0000 | 10056 |
| Label_LEFT.png | 2017-02-13T08:21:48.000+0000 | 10131 |
| Screen Shot 2017-02-12 at 12.24.54.png | 2017-02-12T12:25:11.000+0000 | 11818 |
You should always specify a width when setting the text-alignment for buttons. Working example:
The reason is that the text-alignments also specifes a button inset. So using left produces the insets {left: 10, right: 0} and right produces {right: 10, left: 0}. So when you use, the left insets are 10 and the right are 0, but because you don't specify a fixed width, it auto-sizes and results in this behavior.var win = Ti.UI.createWindow({ backgroundColor: '#fff' }); var button = Ti.UI.createButton({ height: 30, width: 300, title: 'Update status', textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT, backgroundColor: '#DCB5FF' }); win.add(button); win.open();So this is different to the way a label works then as the label adds no insets and justifies correctly. I have added two more images to show this: * Button_LEFT - using a button with text align left * Label_LEFT - using a label with text align left Any idea why the button adds an inset?