UIView autoresizingMask

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使用详解

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.我们的相遇是彼此青春中最美好的邂逅。像春日的暖阳,在这个青春彼此温暖,彼此守候,彼此成长。 我们的友谊始于初中...
    陌璃本无殇阅读 1,181评论 7 7
  • 到现在,我对于阅读基本的理论是,想看的书都先在Kindle上看,如果值得再看就买纸质,如果仅作了解就只看一遍。 大...
    Yi_f588阅读 829评论 2 1