我正在使用约束条件,直到现在还没有问题。Swift - Autolayout 3动态宽度的视图
我有一个tableview,在每一行我有3个标签。这3个标签的内容是动态的,所以我需要这些标签的宽度也是动态的。 事情是,我想要最右边的标签缩小,如果需要显示完整字体大小的左标签和中间标签的全部内容。
正确的标签设置为adjustsFontSizeToFitWidth = true
所以如果需要缩小字体,其他标签具有固定的字体大小。 这里是我迄今为止 -
MainView.addConstraint(NSLayoutConstraint(item: leftlabel,
attribute: .Left,
relatedBy: .Equal,
toItem: MainView,
attribute: .Left,
multiplier: 1,
constant: 15))
MainView.addConstraint(NSLayoutConstraint(item: midlabel,
attribute: .Left,
relatedBy: .Equal,
toItem: leftlabel,
attribute: .Right,
multiplier: 1,
constant: 15))
MainView.addConstraint(NSLayoutConstraint(item: rightlabel,
attribute: .Left,
relatedBy: .Equal,
toItem: midlabel,
attribute: .Right,
multiplier: 1,
constant: 15))
MainView.addConstraint(NSLayoutConstraint(item: rightlabel,
attribute: .Right,
relatedBy: .Equal,
toItem: MainView,
attribute: .Right,
multiplier: 1,
constant: 15))
实际发生的事情是,最左边的标签宽度不断缩小,我看不出它里面的全部文本,而不是我看到的一些文字和3点几封信后。
我想要的另一件事是,即使存在“空白”(例如,如果3个标签内的文本比主视图宽度短),中间标签也会始终位于左侧标签的旁边。
见下图: In the first two rows you can see what I want, and in the last row is what happens