autoresizing代码实现

主要解决父子控件之间的布局关系:
/*
     Flexible 灵活的,自由的
    
     typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
     UIViewAutoresizingNone                 = 0,
     UIViewAutoresizingFlexibleLeftMargin   = 1 << 0,
//   左边是自由的,右边是固定的(与storyboard中 相反)

     UIViewAutoresizingFlexibleWidth        = 1 << 1,
//   宽度是可拉伸的
    
     UIViewAutoresizingFlexibleRightMargin  = 1 << 2,
//    右边是自由的,左边是固定的(与storyboard中 相反)

     UIViewAutoresizingFlexibleTopMargin    = 1 << 3,
//    顶部是自由的,底部是固定的(与storyboard中 相反)

     UIViewAutoresizingFlexibleHeight       = 1 << 4,
//   高度是自由的(高度是可拉伸的)

     UIViewAutoresizingFlexibleBottomMargin = 1 << 5
//    底部是自由的,顶部是固定的(与storyboard中 相反)
     };
    
    
     */
    //四周固定,内部自由
   redView. autoresizingMask =UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
 
    //四周自由,内部固定  redView. autoresizingMask=UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin;
   
    //四周自由,内部也自由    redView.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin;

你可能感兴趣的:(auto)