IOS开发之-控件ContentMode代码改变填充模式小结

UIImageView的使用中,有时需要用代码设置其内图片内容的填充模式,

 为方便以后工作方便查找使用,现把各种模式测试如下


// 测试图片内容填充模式
static int a;
-(void)test1{
    self.imageV.image = [UIImage imageNamed:@"aa.jpg"];
    // 改变内部内容的填充方式
    self.imageV.contentMode = a;
    // 显示模式文字
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 300, 375, 100)];
    NSArray *arr = @[
                      @"UIViewContentModeScaleToFill",      // 拉伸自适应填满整个视图
                      @"UIViewContentModeScaleAspectFit",   // 自适应比例大小显示
                      @"UIViewContentModeScaleAspectFill",  // 原始大小显示
                      @"UIViewContentModeRedraw",           // 尺寸改变时重绘
                      @"UIViewContentModeCenter",           // 中间
                      @"UIViewContentModeTop",              // 顶部
                      @"UIViewContentModeBottom",           // 底部
                      @"UIViewContentModeLeft",             // 中间贴左
                      @"UIViewContentModeRight",            // 中间贴右
                      @"UIViewContentModeTopLeft",          // 贴左上
                      @"UIViewContentModeTopRight",         // 贴右上
                      @"UIViewContentModeBottomLeft",       // 贴左下
                      @"UIViewContentModeBottomRight",      // 贴右下
                     ];
    lab.text = arr[a++];
    lab.font = [UIFont systemFontOfSize:20];
    [self.lab removeFromSuperview];
    [self.imageV addSubview:lab];
    self.lab = lab;
    NSLog(@"%s 模式%d",__func__,a);
    if (a == 13) a = 0;
}

技术分享



版权声明:本文为博主原创文章,未经博主允许不得转载。

文章来自:http://blog.csdn.net/jiisd/article/details/46824189
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3