简体   繁体   中英

Autolayout - UILabel shrinks in width after orientation change, cause by another UILabel which is supposed to auto-adjust font size

I have 2 UILabel side-by-side horizontally using auto-layout as following:

  1. 1st-Label is full-width (like sizeToFit)
  2. 2nd-Label has adjustsFontSizeToFitWidth = true

在此处输入图片说明

On launch everything is fine, when returning from landscape to portrait 1st-Label shrinks to zero width.

Constraints are following:

  • 1st Label: H:|-0-[1stLabel] , V:[1stLabel]-0-|
  • 2nd Label: H:[2ndLabel]-0-| , V:[2ndLabel]-0-|
  • Leading/Trailing Relation Constraint: H:[1stLabel]-(>=1)-[2ndLabel]

将标签1的抗压性优先级设置为1000

我错过了在2nd-Label上设置ContentCompressionResistancePriority的方法:

secondLabel.setContentCompressionResistancePriority(.defaultLow, for:.horizontal)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM