热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

iOS常用技术图片拉伸

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
/********************************************************************/

技术分享


推荐阅读
author-avatar
he恋613_394
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有