问题
I am using static cells with 4 sections to create a Settings scene:
For some cells I use the predefined styles: Right Detail and Basic.
But for the following cells I use Custom style with my own constraints:
- Label on the left and Switch on the right side (like the cell selected in above screenshot)
- Slider occupying the whole cell
My problems: I can not get the leading alignment right and also my 2-lines word-wrapping Label pushes a Switch to the right:
As you can see at the top screenshot, my constraints for the problematic Label in Custom cell are:
- Align Center Y to Superview: 0 pixels
- Leading Space to Superview: 2 pixels (does not match Right Detail and Basic)
- Trailing Space to Switch equal or greater than: 4 pixels (still pushes the Switch too far to the right)
Please help, I wonder how other apps with Settings screens do it.
SOLUTION:
- I have unchecked Constrain to Margins and set Leading Space to 15 pixels (thanks Andre)
- I have solved my 2nd problem by lowering Horizontal Content Compression Resistance Priority of the Label to 250
回答1:
If you use auto-layout,
you can turn on "Preserve Superview Margins" in
- Content View
- Your Label & Switch
- Your custom Table View Cell
and leave Label's leading space and Switch's trailing space to 0 (default)
来源:https://stackoverflow.com/questions/29900537/how-to-align-custom-cells-to-right-detail-and-basic-cells