图片填充模式

一、常用填充模式

  • UIViewContentModeScaleToFill 变形塞满;

  • UIViewContentModeScaleAspectFit 等比例不超出显示,大概率会有部分边缘空白;

  • UIViewContentModeScaleAspectFill 原图比例显示,大概率图片会溢出;

二、拉伸

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight
leftCapWidth: 水平拉伸;拉伸区域为 x = leftCapWidth + 1个像素;
topCapHeight:竖直拉伸;拉伸区域为 y = topCapHeight + 1个像素;

        

 

 

样例代码

UIImageView *imgV1 = [[UIImageView alloc]initWithFrame:CGRectMake(20, 80, 340, 700)];
    imgV1.backgroundColor = [UIColor orangeColor];
    UIImage *img1 = [UIImage imageNamed:@"1"];
    img1 = [img1 stretchableImageWithLeftCapWidth:img1.size.width*0.5 topCapHeight:img1.size.height*0.5];
    imgV1.image = img1;
    [self.view addSubview:imgV1];


 

 


 

posted @   ~道一~  阅读(274)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示