代码笔记使图片两边不拉伸,中间拉伸

Posted 菜鸟and小白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了代码笔记使图片两边不拉伸,中间拉伸相关的知识,希望对你有一定的参考价值。

代码:

复制代码
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //使图片两边不拉伸,中间拉伸
    UIImage *image = [UIImage imageNamed:@"1.jpg"];
    image = [image stretchableImageWithLeftCapWidth:floorf(image.size.width/2) topCapHeight:floorf(image.size.height/2)];
    
    UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 200, 200)];
    imageView.backgroundColor=[UIColor redColor];
    imageView.image=image;
    [self.view addSubview:imageView];
}
复制代码

 

 

 
 

以上是关于代码笔记使图片两边不拉伸,中间拉伸的主要内容,如果未能解决你的问题,请参考以下文章