ios - adjustsFontSizeToFitWidth not working when change constraints? -


i have costview holds uilabel dollarsign , uilabel cost. this how dollarsign being constrained. this how cost being constrained.

in addviewcontroller changed of constraints, including height of costview

class addviewcontroller: uiviewcontroller {   @iboutlet weak var costview: uiview! @iboutlet weak var statusbarheight: nslayoutconstraint! @iboutlet weak var navigationbar: uinavigationbar! @iboutlet weak var dollarsign: uilabel! @iboutlet weak var cost: uilabel! @iboutlet weak var keyboardheight: nslayoutconstraint! @iboutlet weak var costviewheight: nslayoutconstraint!  override func viewdidload() {     super.viewdidload()      //set size of cost view & numbers keyboard     let halfviewheight = (view.bounds.height - statusbarheight.constant - navigationbar.bounds.height)/2     costviewheight.constant = halfviewheight/cgfloat(4)     keyboardheight.constant = halfviewheight - costviewheight.constant      //adjust font size of dollar sign & cost     cost.adjustsfontsizetofitwidth = true     print("cost frame: \(cost.frame)")     dollarsign.adjustsfontsizetofitwidth = true     print("dollar sign frame: \(dollarsign.frame)") } } 

when load app, constraints costviewheight & keyboardheight update , rearrange accordingly. however, font size of labels dollarsign , cost not adjust themselves, as can see here.

after adding 2 lines in here:

    //adjust font size of dollar sign & cost     cost.adjustsfontsizetofitwidth = true     cost.backgroundcolor = uicolor.redcolor() //add line     print("cost frame: \(cost.frame)")     dollarsign.adjustsfontsizetofitwidth = true     dollarsign.backgroundcolor = uicolor.redcolor() //add line     print("dollar sign frame: \(dollarsign.frame)") 

you can see frame of cost , dollarsign readjust fit in new constraints.

question: since used .adjustsfontsizetofitwidth = true, why isn't font size changing after change height? .adjustfontsizetofitwidth work when change width? if so, how can make .adjustfontsizetofitheight method?

a strange thing noticed may or not relevant when printed out cost , dollarsign frames same frames listed on storyboard (cost frame , dollarsign frame).

cost frame: (567.0, 7.5, 14.5, 34.0) dollar sign frame: (8.0, 8.0, 15.0, 34.0) 

this strange b/c since changed height of costview frames of cost , dollarsign should change(which do). if cost , dollarsign frame changes why don't numbers change?


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -