现在的位置: 首页 > 综合 > 正文

背景平铺和拉伸

2013年12月12日 ⁄ 综合 ⁄ 共 671字 ⁄ 字号 评论关闭

1. 背景repeat (不以拉伸方式显示背景,而是用repeat的方式)

问:UILabel 如何实现css这个效果:.iphone { padding: 8px 20px; height: 33px; background:url(bg_iphone_title.png)
0 -36px repeat-x; text-align:left; }

求助,就是设置视图的背景,本来是1x480的图,横向循环背景图实现320x480,而不是拉伸来铺满视图,哪位大大知道

答:+
(UIColor *)colorWithPatternImage:(UIImage *)image

2.
图片拉伸

问:facebook
里面的 Tab 按钮,其实这个问题主要是问如何把一张图片进行9宫切割式的拉伸:

iphone开发小技巧-背景repeat,图片拉伸

原图是这样的:

iphone开发小技巧-背景repeat,图片拉伸

也可以是这样的气泡图

iphone开发小技巧-背景repeat,图片拉伸

原图是这样的

iphone开发小技巧-背景repeat,图片拉伸iphone开发小技巧-背景repeat,图片拉伸

答:[[UIImageView alloc] initWithImage:[origintalImage stretchableImageWithLeftCapWidth:leftCapWidth
topCapHeight:topCapHeight]]

 

leftCapWidth 和 topCapHeight所指定的四边不会被拉伸

rightCapWIdth = image.width - leftCapWidth - 1, bottomCapHeight同理
举个例子一个图片像素是80

如果设置leftCapWidth的值为20

那它就会从图片从左到右的第二十个像素开始拉伸

其他部位不会拉伸,说白就是在那个位置不停复制那个位置的那条线以达到拉伸效果



如图中, 只有绿色部分会被拉伸缩放

iphone开发小技巧-背景repeat,图片拉伸

抱歉!评论已关闭.