美文网首页
UIView autoresizingMask

UIView autoresizingMask

作者: Rumbles | 来源:发表于2018-09-02 11:30 被阅读5次

    iOS有两大自动布局利器

    autoresizing

    UIViewAutoresizing是一个枚举类型,默认是UIViewAutoresizingNone,也就是不做任何处理。
    
    typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
        UIViewAutoresizingNone                 = 0,  不会随父视图的改变而改变
        UIViewAutoresizingFlexibleLeftMargin   = 1 << 0, 自动调整view与父视图左边距,以保证右边距不变
        UIViewAutoresizingFlexibleWidth        = 1 << 1, 自动调整view的宽度,保证左边距和右边距不变
        UIViewAutoresizingFlexibleRightMargin  = 1 << 2, 自动调整view与父视图右边距,以保证左边距不变
        UIViewAutoresizingFlexibleTopMargin    = 1 << 3, 自动调整view与父视图上边距,以保证下边距不变
        UIViewAutoresizingFlexibleHeight       = 1 << 4, 自动调整view的高度,以保证上边距和下边距不变
        UIViewAutoresizingFlexibleBottomMargin = 1 << 5, 自动调整view与父视图的下边距,以保证上边距不变
    };
            UIView *badge = [UIImageView new];
            badge.backgroundColor = [UIColor blueColor];
            badge.userInteractionEnabled = NO;
            badge.contentMode = UIViewContentModeScaleAspectFit;
            badge.size = CGSizeMake(56 / 2, 36 / 2);
            badge.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
            badge.right = imageView.width;
            badge.bottom = imageView.height;
            badge.hidden = YES;
            imageView.backgroundColor = [UIColor blackColor];
            [imageView addSubview:badge];
    

    autolayout

    masonry

    UIViewContentMode

    图片大 会充满 裁剪。 图片小会 显示在左面或者有面
    @"UIViewContentModeScaleToFill",          // 拉伸自适应填满整个视图
    @"UIViewContentModeScaleAspectFit",   // 自适应比例大小显示  宽或者高 充满
    @"UIViewContentModeScaleAspectFill",  // 原始大小显示   充满。但是需要裁剪
    @"UIViewContentModeRedraw",               // 尺寸改变时重绘 
    @"UIViewContentModeCenter",                 // 中间   充满 显示中间
    @"UIViewContentModeTop",                      // 顶部  充满 显示顶部
    @"UIViewContentModeBottom",               // 底部  充满 显示底部
    @"UIViewContentModeLeft",                     // 中间贴左
    @"UIViewContentModeRight",                    // 中间贴右
    @"UIViewContentModeTopLeft",                // 贴左上
    @"UIViewContentModeTopRight",             // 贴右上
    @"UIViewContentModeBottomLeft",         // 贴左下
    @"UIViewContentModeBottomRight",      // 贴右下
    

    自动布局之autoresizingMask使用详解

    相关文章

      网友评论

          本文标题:UIView autoresizingMask

          本文链接:https://www.haomeiwen.com/subject/jqxmwftx.html