首页 > 学院 > 开发设计 > 正文

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

2019-11-14 19:30:43
字体:
来源:转载
供稿:网友
A.转发微博部分的淡灰色背景
1.需求
  • 转发微博部分需要设置背景色
  • 使用图片作为背景
 
2.思路
方法有:
  • 直接设置view的背景图片,使用UIColor的平铺图片
  • 实现view的drawRect方法,拉伸背景图片(把背景图片画到整个view上)
  • 令转发微博view继承ImageView,直接设置图片,这样还可以设置高亮图片
 
3.实现
(1)直接设置backgroundColor,平铺图片
1         // 设置背景2         // 使用平铺方式设置背景图片3         self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithNamed:@"timeline_retweet_background"]];
 
但是由于是平铺图片,图片的上下边缘部分会形成很多"细线"
Image(152)
 
(2)实现drawRect
1 - (void)drawRect:(CGRect)rect {2     [[UIImage imageWithNamed:@"timeline_retweet_background"] drawInRect:self.bounds];3 }
 
Image(153)
 
(3)改变view的父类为ImageView,直接设置image属性
1         // 设置背景图片2         [self setImage:[UIImage imageWithNamed:@"timeline_retweet_background"]];3         [self setHighlightedImage:[UIImage imageWithNamed:@"timeline_retweet_background_highlighted"]];
 
Image(154)
 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表