[iOS微博项目-4.2]-设置转发微博背景

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

github:https://github.com/hellovoidworld/HVWWeibo

A.转发微博部分的淡灰色背景

1.需求

转发微博部分需要设置背景色使用图片作为背景

2.思路

方法有:

直接设置view的背景图片,使用UIColor的平铺图片实现view的drawRect方法,拉伸背景图片(把背景图片画到整个view上)令转发微博view继承ImageView,直接设置图片,这样还可以设置高亮图片

3.实现

(1)直接设置backgroundColor,平铺图片

1//设置背景2//使用平铺方式设置背景图片3self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithNamed:@"timeline_retweet_background"]];

但是由于是平铺图片,图片的上下边缘部分会形成很多"细线"

(2)实现drawRect

1- (void)drawRect:(CGRect)rect {2[[UIImage imageWithNamed:@"timeline_retweet_background"] drawInRect:self.bounds];3}

(3)改变view的父类为ImageView,直接设置image属性

1//设置背景图片2[self setImage:[UIImage imageWithNamed:@"timeline_retweet_background"]];3[self setHighlightedImage:[UIImage imageWithNamed:@"timeline_retweet_background_highlighted"]];

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航