代码:

【代码笔记】iOS-使图片两边不拉伸,中间拉伸
- (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];
}
【代码笔记】iOS-使图片两边不拉伸,中间拉伸

 

 

 
 

代码:

【代码笔记】iOS-使图片两边不拉伸,中间拉伸
- (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];
}
【代码笔记】iOS-使图片两边不拉伸,中间拉伸

 

 

相关文章:

  • 2022-01-02
  • 2021-06-04
  • 2021-11-20
  • 2021-11-04
  • 2021-11-26
  • 2021-12-05
  • 2021-10-09
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2021-10-12
  • 2022-12-23
  • 2022-02-12
  • 2021-12-29
相关资源
相似解决方案