Can't change default layoutMargins of view

前端 未结 3 625
深忆病人
深忆病人 2021-01-13 09:26

Since ios 8.0 views have additional layoutMargins which by default has an 8 points values for every side.

When I try to change margins in viewDidL

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-13 09:56

    I used KVO to detect the view.layoutMargins changes. And I found that the view itself would change the layoutMargins after customise during layoutSubViews processing.

    So just put your customise codes in viewDidLayoutSubviews method:

    - (void)viewDidLayoutSubviews
    {
        self.view.layoutMargins = UIEdgeInsetsMake(100.0f, 100.0f, 100.0f, 100.0f);
    }
    

    PS: Through these codes are OC, but I think it can also work for Swift. Hope this works for you!

提交回复
热议问题