How to align Custom cells to Right Detail and Basic cells?

落爺英雄遲暮 提交于 2020-01-17 03:35:32

问题


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:

  1. I have unchecked Constrain to Margins and set Leading Space to 15 pixels (thanks Andre)
  2. 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

  1. Content View
  2. Your Label & Switch
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!