DJStatusToolBar.m

// 添加按钮
- (UIButton *)setupBtn:(NSString *)title image:(NSString *)imageName {

    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 8, 0, 0)];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [self addSubview:btn];
    
    [self.btns addObject:btn];
    return btn;
}

 

- (void)setStatus:(DJStatus *)status {

    _status = status;

    // 转发
    [self setCount:status.reposts_count title:@"转发" button:self.retweetBtn];
    // 评论
    [self setCount:status.comments_count title:@"评论" button:self.commentBtn];
    //
    [self setCount:status.attitudes_count title:@"" button:self.altitudeBtn];
    
}



- (void)setCount:(int)count title:(NSString *)title button:(UIButton *)btn  {
    
    if (count) {
        if (count > 10000) {
            double wan = count / 10000.0;
            title = [NSString stringWithFormat:@"%.1f万",wan];
            // 将出现的.0去掉,如:10.0万->10万
            title = [title stringByReplacingOccurrencesOfString:@".0" withString:@""];
        } else {
            title = [NSString stringWithFormat:@"%d",count];
        }
    }
    
    [btn setTitle:title forState:UIControlStateNormal];
    
}

 

最终效果:

新浪微博客户端(27)-格式化工具条显示数字 

相关文章:

  • 2021-04-29
  • 2021-11-21
  • 2021-06-03
  • 2022-03-03
  • 2021-12-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-29
  • 2021-09-15
  • 2021-05-31
  • 2021-11-21
  • 2021-06-19
  • 2021-10-08
  • 2021-04-02
相关资源
相似解决方案