答案 0 :(得分:1)
您需要向滑块对象添加宽度约束:
// add age slider constraints to age view. ageView is the container of the ageSlider
// center ageSlider both horizontally and vertically
ageSlider.centerXAnchor.constraint(equalTo: ageView.centerXAnchor).isActive = true
ageSlider.centerYAnchor.constraint(equalTo: ageView.centerYAnchor).isActive = true
// constrain ageSlider width to 90% of ageView width
ageSlider.widthAnchor.constraint(equalTo: ageView.widthAnchor, multiplier: 0.9).isActive = true
答案 1 :(得分:1)
如果要手动设置UI组件的false
,请不要将translatesAutoresizingMaskIntoConstraints
设置为frame
。
将其设置为true:
ageS.translatesAutoresizingMaskIntoConstraints = true
或仅注释该行。
如果您希望大小不是静态的,并在电话方向更改或超级视图的框架更改时更改...,则使用约束。就您而言,您缺少宽度限制。