[iOS微博项目

A.设置每条微博边框样式
1.需求
不需要分割线
每个微博之间留有一定的间隙
 
2.思路
  • 直接设置分割线样式为none就可以去除分割线
  • 设置tableView的背景色
  • 让每个cell的y值下移10个单位,做出间隙效果
  • 使用资源包内的背景图片类填充cell背景
 
3.实现
(1)去除默认分割线
 1 //  HVWHomeViewController.m
 2 - (void)viewDidLoad {
 3     [super viewDidLoad];
 4    
 5     self.tableView.delegate = self;
 6    
 7     // 设置导航栏
 8     [self setupNavigationBar];
 9    
10     // 获取用户信息
11     [self setupUserInfo];
12    
13     // 添加刷新器
14     [self addRefresh];
15    
16     // 设置tableView背景颜色
17     self.tableView.backgroundColor = HVWColor(211, 211, 211);
18     // 设置"不需要分割线"
19     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
20 }
 
Image(155)
 
(2)设置每个cell之间的间隙
a.每个微博内容frame下移10个单位
1 //  HVWStatusContentFrame.m
2     // 自己的frame
3     CGFloat contentX = 0;
4     CGFloat contentY = 10; // 下移10个单位
5     CGFloat contentWidth = HVWScreenWidth;
6     self.frame = CGRectMake(contentX, contentY, contentWidth, contentHeight);
 
b.清除cell背景色
 1 //  HVWStatusCell.m
 2 /** 创建 */
 3 + (instancetype) cellWithTableView:(UITableView *)tableView {
 4     static NSString *ID = @"HVWStatusCell";
 5     HVWStatusCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
 6    
 7     if (nil == cell) {
 8         cell = [[self alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
 9     }
10    
11     // 清空cell背景色
12     cell.backgroundColor = [UIColor clearColor];
13    
14     return cell;
15 }
 
c.设置微博view继承UIImageView,设置image(就是为了拉伸背景图片)
 1 //  HVWStatusContentView.m
 2 - (instancetype)initWithFrame:(CGRect)frame {
 3     self = [super initWithFrame:frame];
 4    
 5     if (self) { // 初始化子控件开始
 6         // 设置背景图片
 7         self.image = [UIImage resizedImage:@"timeline_card_top_background"];
 8         self.highlightedImage = [UIImage resizedImage:@"timeline_card_top_background_highlighted"];
 9        
10         // 初始化原创内容控件
11         [self setupOriginalView];
12        
13         // 初始化转发内容控件
14         [self setupRetweetedView];
15     }
16    
17     return self;
18 }
 
Image(156)
 
 
原文地址:https://www.cnblogs.com/hellovoidworld/p/4311072.html