iOS常用技术-图片拉伸

 1 //
 2 //  ViewController.m
 3 //  图片拉伸
 4 //
 5 //  Created by 大欢 on 16/1/20.
 6 //  Copyright © 2016年 bjsxt. All rights reserved.
 7 //
 8 
 9 #import "ViewController.h"
10 
11 @interface ViewController ()
12 
13 @end
14 
15 @implementation ViewController
16 
17 - (void)viewDidLoad {
18     [super viewDidLoad];
19     
20 //    [self exmaple1];
21 //    [self exmaple2];
22     
23     UIImage * image = [UIImage imageNamed:@"button_back"];
24     
25     UIEdgeInsets insets = UIEdgeInsetsMake(5, 2, 5, 2);
26     
27     image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
28     
29     UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(12, 50 , self.view.frame.size.width - 24, 40)];
30     
31     imageView.image = image;
32     
33     [self.view addSubview:imageView];
34     
35     
36 }
37 
38 - (void)exmaple2 {
39     
40     UIImage * image = [UIImage imageNamed:@"qipao"];
41     
42     UIEdgeInsets insets = UIEdgeInsetsMake(50, 35, 10, 10);
43     
44     image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
45     
46     UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(30, 50, 300, 300)];
47     
48     imageView.image = image;
49     
50     [self.view addSubview:imageView];
51 }
52 
53 - (void)exmaple1 {
54     
55     UIImage * image = [UIImage imageNamed:@"backgroundImage"];
56     
57     //上,左,下,右
58     UIEdgeInsets insets = UIEdgeInsetsMake(6, 6, 6, 6);
59     
60     //拉伸图片方法
61     image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
62     
63     UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 30, self.view.frame.size.width - 40, 30)];
64     
65     imageView.image = image;
66     
67     [self.view addSubview:imageView];
68 }
69 
70 @end

 


/********************************************************************/

posted @ 2016-01-20 21:40  MrWuYindi  阅读(182)  评论(0编辑  收藏  举报