How do I change UIView Size?

前端 未结 8 1976
抹茶落季
抹茶落季 2020-12-07 23:48

I have trouble with modifying my UIView height at launch.

I have to UIView and I want one to be screen size * 70 and the other to fill the gap.

here is what

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 00:41

    I know that there is already a solution to this question, but I found an alternative to this issue and maybe it could help someone.

    I was having trouble with setting the frame of my sub view because certain values were referring to its position within the main view. So if you don't want to update your frame by changing the whole frame via CGRect, you can simply change a value of the frame and then update it.

    // keep reference to you frames
    var questionView = questionFrame.frame
    var answerView = answerFrame.frame
    
    // update the values of the copy        
    questionView.size.height = CGFloat(screenSize.height * 0.70)
    answerView.size.height = CGFloat(screenSize.height * 0.30)
    
    // set the frames to the new frames
    questionFrame.frame = questionView
    answerFrame.frame = answerView
    

提交回复
热议问题