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"]];