ios25---图片拉伸

控制器:
//
// ViewController.m
// 12-图片的拉伸问题
//
// Created by xiaomage on 15/12/30.
// Copyright © 2015年 小码哥. All rights reserved.
// #import "ViewController.h"
#import "UIImage+XMGExtention.h" @interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *button; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// 1.1 创建UIImage对象
UIImage *image = [UIImage resizableImageWithLocalImageName:@"car"];//扩展了系统类的方法 //UIImage *image = [UIImage imageNamed:@"car"]; // 1.2 拿到image的尺寸
/*
CGFloat imageWidth = image.size.width;
CGFloat imageHeight = image.size.height;
*/ // 1.3 返回一张受保护而且拉伸的图片 --->CapInsets:哪些地方要保护:上面保护图片高度一半,左边保护图片宽度一半,右边保护宽度一半减一,下面保护高度一半减一。只有中间1*1的区域拉伸。 // 方式一
/*
UIImage *resizableImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(imageHeight * 0.5, imageWidth * 0.5, imageHeight * 0.5 -1, imageWidth * 0.5 - 1)]; UIImageResizingModeTile, 平铺
UIImageResizingModeStretch, 拉伸(伸缩) UIImage *resizableImage = [image resizableImageWithCapInsets:UIEdgeInsetsMake(imageHeight * 0.5, imageWidth * 0.5, imageHeight * 0.5 -1, imageWidth * 0.5 - 1) resizingMode:UIImageResizingModeTile];
*/ // 方式二
/*
// 右边需要保护的区域 = 图片的width - leftCapWidth - 1
// bottom cap = height - topCapHeight - 1
UIImage *resizableImage = [image stretchableImageWithLeftCapWidth:imageWidth * 0.5 topCapHeight:imageHeight * 0.5];
*/ //2.把图片设置到按钮上
[self.button setBackgroundImage:image forState:UIControlStateNormal]; } @end
UIImage的扩展,分类:
//
// UIImage+XMGExtention.h
// 12-图片的拉伸问题
// #import <UIKit/UIKit.h> @interface UIImage (XMGExtention) //分类
/**
* 返回一张受保护的图片(被拉伸的)
*/
+ (instancetype)resizableImageWithLocalImageName: (NSString *)localImageName;
@end
//
// UIImage+XMGExtention.m
// #import "UIImage+XMGExtention.h" @implementation UIImage (XMGExtention) + (instancetype)resizableImageWithLocalImageName:(NSString *)localImageName{
// 创建图片对象
UIImage *image = [UIImage imageNamed:localImageName]; // 获取图片的尺寸
CGFloat imageWidth = image.size.width;
CGFloat imageHeiht = image.size.height; // 返回一张拉伸且受保护的图片
return [image stretchableImageWithLeftCapWidth:imageWidth * 0.5 topCapHeight:imageHeiht * 0.5 ];
}
@end
ios25---图片拉伸的更多相关文章
- iOS图片拉伸技巧
纵观移动市场,一款移动app,要想长期在移动市场立足,最起码要包含以下几个要素:实用的功能.极强的用户体验.华丽简洁的外观.华丽外观的背后,少不了美工的辛苦设计,但如果开发人员不懂得怎么合理展示这些设 ...
- 【原】iOS学习之图片拉伸处理(类似qq的气泡)
原理是拉伸里面的内容,将边保护起来 方法1: ①[image resizableImageWithCapInsets:UIEdgeInsetsMake(, , , )]; ②[image resiza ...
- iOS开发——UI基础-按钮内边距,图片拉伸
一.内边距 UIButton有三个属性,分别可以设置按钮以及内部子控件的内边距 1.contentEdgeInsets 如果是设置contentEdgeInsets, 会把UIImageView和UI ...
- (转)iOS图片拉伸技巧
( 原文博客地址: http://blog.csdn.net/q199109106q/article/details/8615661) 纵观移动市场,一款移动app,要想长期在移动市场立足,最起码要 ...
- IOS中图片拉伸技巧与方法总结(转载)
以下内容转载自:http://my.oschina.net/u/2340880/blog/403996 IOS中图片拉伸技巧与方法总结 一.了解几个图像拉伸的函数和方法 1.直接拉伸法 简单暴力,却是 ...
- iOS杂谈-图片拉伸的实现
如上图是一个按钮的背景图,在Android上,很多图片资源都是类似这样子的,但是由于按钮的高度及宽度与图片的世纪尺寸不同,所以需要采用9patch来实现拉伸处理, 可参考:http://www.cnb ...
- iOS 图片拉伸的解释
以前对于ios的图片拉伸参数一直不太理解,终于看到一篇好文章,转载一下,原文地址:http://blog.csdn.net/q199109106q/article/details/8615661 主要 ...
- css背景图片拉伸 以及100% 满屏显示
如何用css背景图片拉伸 以及100% 满屏显示呢?这个问题听起来似乎很简单.但是很遗憾的告诉大家.不是我们想的那么简单. 比如一个容器(body,div,span)中设定一个背景.这个背景的长宽值在 ...
- 我的Android最佳实践之—— ImageView中图片拉伸显示
通过设置android:scaleType="fitXY"使得图片拉伸显示.补充:scaleType的属性有matrix(默认).center.centerCrop.centerI ...
- 博主教你制作类似9patch效果的iOS图片拉伸
下面张图片,本来是设计来做按钮背景的: button.png,尺寸为:24x60 现在我们把它用作为按钮背景,按钮尺寸是150x50: // 得到view的尺寸 CGSize viewSize = ...
随机推荐
- vue 轮播插件使用
<template> <div> <Swiper ref="swiper" v-if="list.length > 0" : ...
- Python多线程豆瓣影评API接口爬虫
爬虫库 使用简单的requests库,这是一个阻塞的库,速度比较慢. 解析使用XPATH表达式 总体采用类的形式 多线程 使用concurrent.future并发模块,建立线程池,把future对象 ...
- Springboot和SpringMVC区别
Springboot和SpringMVC区别----http://www.cnblogs.com/xdyixia/p/9279644.html
- 九度oj 题目1525:子串逆序打印
题目1525:子串逆序打印 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:3124 解决:530 题目描述: 小明手中有很多字符串卡片,每个字符串中都包含有多个连续的空格,而且这些卡片在 ...
- Codeforces Round #364 (Div. 2),只有A与B
A. Cards time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- tarjan 割点 割边
by GeneralLiu tarjan 求 割点 割边 无向图 的 割点 割边: 对于无向连通图来说, 如果删除 一个点以及与它相连的边 之后, 使得这个图不连通, 那么该点为割点 : ...
- Thinkphp5.0 的实践一
Thinkphp5.0 的实践一 tp5.0默认没有__SELF__,需要定义, define('__SELF__',strip_tags($_SERVER['REQUEST_URI'])); tp5 ...
- Elasticsearch的Java API做类似SQL的group by聚合。
https://www.cnblogs.com/kangoroo/p/8033955.html
- 博弈论入门题 kiki's game
Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his mind ...
- 转 POJ分类
OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...