【发布时间】:2015-10-19 10:21:13
【问题描述】:
我有一个自定义单元格,需要并排布局两个 UILabel。两个标签的宽度都是动态的并且可以换行。
我定义的自动布局在以下情况下会失败
- 滚动单元格及其包含的部分,使其全部显示在屏幕上。
- 将设备旋转到横向(需要足够大的 View 以便单元格在屏幕上)
- 向后旋转,左侧标签将被压缩。
如果整个单元格和包含的部分在旋转之前不在屏幕上,则布局不会失败
这里是它工作和旋转后的几个屏幕截图
这是具有以下约束的布局
this.ContentView.AddConstraint(
NSLayoutConstraint.Create(
this.TextLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Left,
1.0f, (nfloat)LeftRightPadding));
this.ContentView.AddConstraint(
NSLayoutConstraint.Create(
this.TextLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Top,
1.0f, (nfloat)TopAndBottomPadding));
this.ContentView.AddConstraint(
NSLayoutConstraint.Create(
this.TextLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Bottom,
1.0f, 0 - (nfloat)TopAndBottomPadding));
this.ContentView.AddConstraint(
NSLayoutConstraint.Create(
this.DetailTextLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Right,
1.0f, 0 - (nfloat)LeftRightPadding));
this.ContentView.AddConstraint(
NSLayoutConstraint.Create(
this.DetailTextLabel, NSLayoutAttribute.Top, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Top,
1.0f, (nfloat)TopAndBottomPadding));
this.ContentView.AddConstraint(
NSLayoutConstraint.Create(
this.DetailTextLabel, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Bottom,
1.0f, 0 - (nfloat)TopAndBottomPadding));
this.ContentView.AddConstraint(
NSLayoutConstraint.Create(
this.DetailTextLabel, NSLayoutAttribute.Left, NSLayoutRelation.Equal, this.TextLabel, NSLayoutAttribute.Right,
1.0f,
10));
如何阻止左侧标签的挤压?
【问题讨论】:
-
增加左压缩阻力?
标签: ios xamarin.ios autolayout