Autoresizing

一丶 Autoresizing


1.1 摘要: 蘋果在iOS2中引入了Autoresizing技術(shù)用于屏幕適配, 用于在其父視圖的bounds發(fā)生改變時(shí)如何自動調(diào)整如何調(diào)整自身布局(大小)

1.2 使用:
  • ?? Autoreszing 與 Auto Layout 二者不能共存,Xcode中默認(rèn)開啟了Autolayout技術(shù), 在使用Autoresizing技術(shù)前需要手動將其關(guān)閉


    關(guān)閉Auto Layout.png
  • autoresizingMask屬性: autoresizingMask屬性的設(shè)置由六根線標(biāo)識, 其中位于外部的四根線分別用于標(biāo)識用于父視圖的bounds發(fā)生改變時(shí)自動調(diào)整與父視圖的上、下、左、右邊距; 位于內(nèi)部的兩根線分別用于標(biāo)識如何自動調(diào)整自身的寬度和高度
  • 默認(rèn)autoresizingMask標(biāo)識的情況下
    autoresizingMask屬性.png
    默認(rèn)autoresizingMask標(biāo)識.jpg
  • 設(shè)置autoresizingMask距離父視圖的右邊與底部的標(biāo)識
    距離父視圖的右邊與底部的標(biāo)識.png
    效果圖
  • 設(shè)置autoresizingMask自動調(diào)整自身的寬度和高度


    距離父視圖的右邊與底部的標(biāo)識.png

    自動調(diào)整自身的寬度和高度效果圖.png
  • 代碼實(shí)現(xiàn)

    /*
     UIViewAutoresizingNone                 = 0, //不會根據(jù)父控件的改變而進(jìn)行改變
     UIViewAutoresizingFlexibleLeftMargin   = 1 << 0, 自動調(diào)整距離父控件左邊邊距(也就是距離右邊邊距是固定的)
     UIViewAutoresizingFlexibleWidth        = 1 << 1, 自動調(diào)整寬度根據(jù)父控件的寬度發(fā)生變化而變化
     UIViewAutoresizingFlexibleRightMargin  = 1 << 2, 自動調(diào)整距離父控件u右邊邊距
     UIViewAutoresizingFlexibleTopMargin    = 1 << 3, 自動調(diào)整距離父控件頂部邊距
     UIViewAutoresizingFlexibleHeight       = 1 << 4, 自動調(diào)整高度根據(jù)父控件的高度發(fā)生變化而變化
     UIViewAutoresizingFlexibleBottomMargin = 1 << 5  自動調(diào)整距離父控件底部邊距
     */
    CGFloat H = [UIScreen mainScreen].bounds.size.height;
    CGFloat W = [UIScreen mainScreen].bounds.size.width;
    UIView *blueView =  [[UIView alloc] initWithFrame:CGRectMake(W-100, H-100, 100, 100)];
    blueView.backgroundColor = [UIColor blueColor];
    blueView.autoresizingMask  = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    [self.view addSubview:blueView];

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容