作者:he恋613_394 | 来源:互联网 | 2023-09-17 14:43
ViewController.m图片拉伸Createdby大欢on16120.Copyright©2016年bjsxt.Allrightsreserved.#importView
//
// ViewController.m
// 图片拉伸
//
// Created by 大欢 on 16/1/20.
// Copyright © 2016年 bjsxt. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// [self exmaple1];
// [self exmaple2];
UIImage * image = [UIImage imageNamed:@"button_back"];
UIEdgeInsets insets = UIEdgeInsetsMake(5, 2, 5, 2);
image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(12, 50 , self.view.frame.size.width - 24, 40)];
imageView.image = image;
[self.view addSubview:imageView];
}
- (void)exmaple2 {
UIImage * image = [UIImage imageNamed:@"qipao"];
UIEdgeInsets insets = UIEdgeInsetsMake(50, 35, 10, 10);
image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(30, 50, 300, 300)];
imageView.image = image;
[self.view addSubview:imageView];
}
- (void)exmaple1 {
UIImage * image = [UIImage imageNamed:@"backgroundImage"];
//上,左,下,右
UIEdgeInsets insets = UIEdgeInsetsMake(6, 6, 6, 6);
//拉伸图片方法
image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, self.view.frame.size.width - 40, 30)];
imageView.image = image;
[self.view addSubview:imageView];
}
@end
/********************************************************************/