簡體   English   中英

UIView autoresizingMask用於固定左右邊距和靈活寬度

[英]UIView autoresizingMask for fixed left and right margin and flexible width

我無法弄清楚如何使用固定的左右邊距調整寬度。 自動調整xCode

我沒有找到任何固定的領先/右邊距API。

在代碼中,要使視圖具有固定的左右邊距以及靈活的寬度,您可以執行以下操作:

UIView *parentView = self.view; // adjust as needed
CGRect bounds = parentView.bounds; // get bounds of parent view
CGRect subviewFrame = CGRectInset(bounds, 20, 0); // left and right margin of 20
UIView *subview = [[UIView alloc] initWithFrame:subviewFrame];
subview.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[parentView addSubview:subview];

根據需要進行調整以創建實際的子視圖。 調整subviewFrame以匹配所需的邊距。

如上所述,這將為您的子視圖提供固定的左右邊距,每個邊距為20個點,並具有靈活的寬度。 設置autoresizingMask ,任何未設置為靈活的組件都會自動修復(幾乎)。 這意味着上邊距和高度也是固定的(因為它們未設置)。 由於上邊距和高度是固定的,因此底邊距是隱式靈活的。 由於顯而易見的原因,所有三個值都不能同時修復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM