·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> [iOS微博项目-4.2]-设置转发微博背景

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

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23
github: https://github.com/hellovoidworld/HVWWeibo
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)