iOS 基本视图创建-UIImageView

测试图片:100*100

1.基本创建

    UIImageView *IconView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 200, 300, 300)];
    IconView.center = self.view.center;
    IconView.image = [UIImage imageNamed:@"test.png"];
    IconView.backgroundColor = UIColor.blueColor;
    [self.view addSubview:IconView];

2.UIimageView的UIViewContentMode设置

    UIViewContentModeScaleToFill,//图片拉伸填满不超出

    UIViewContentModeScaleAspectFit, //图片的高或者宽拉伸与视图的高或者宽相等

    UIViewContentModeScaleAspectFill,   //图片短的高或者宽充满整个视图长部分的超出视图

    UIViewContentModeRedraw, //  重绘图片效果 ScaleToFill差不多反正看不出什么差别          

    UIViewContentModeCenter,  //图片不拉伸 位于视图正中间位置 图片大于视图超出视图         

    UIViewContentModeTop, //图片不拉伸 位于视图top中间位置 图片大于视图超出视图 

    UIViewContentModeBottom, //图片不拉伸 位于视图bottom中间位置 图片大于视图超出视图 

    UIViewContentModeLeft, //图片不拉伸 位于视图left中间位置 图片大于视图超出视图 

    UIViewContentModeRight, //图片不拉伸 位于视图right中间位置 图片大于视图超出视图 

    UIViewContentModeTopLeft,//图片不拉伸 位于视图上左位置 图片大于视图超出视图 

    UIViewContentModeTopRight,//图片不拉伸 位于视图上有位置 图片大于视图超出视图 

    UIViewContentModeBottomLeft,//图片不拉伸 位于视图下左位置 图片大于视图超出视图 

    UIViewContentModeBottomRight,//图片不拉伸 位于视图下右位置 图片大于视图超出视图 


猜你喜欢

转载自blog.csdn.net/zhjw1991/article/details/80452360