iOS图片拉伸的4种方法-创新互联
假如下面的一张图片,是用来做按钮的背景图片的,原始尺寸是(128 * 112)
按钮背景图片.png
我们通过代码将这张图片设置为按钮的背景图片,假如我们将创建好的按钮的宽高设置为:(W=200, H=50)代码如下:
// // ViewController.m // iOS图片拉伸总结 // // Created by Sunshine on 15/6/29. // Copyright (c) 2015年 YotrolZ. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // 创建一个按钮 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; // 设置按钮的frame btn.frame = CGRectMake(100, 300, 200, 50); // 加载图片 UIImage *image = [UIImage imageNamed:@"chat_send_nor"]; // 设置按钮的背景图片 [btn setBackgroundImage:image forState:UIControlStateNormal]; // 将按钮添加到控制器的view [self.view addSubview:btn]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章题目:iOS图片拉伸的4种方法-创新互联
文章起源:http://tyjierui.cn/article/ggide.html