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


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

    最终效果:

     

  • 相关阅读:
    LOJ#2245 魔法森林
    洛谷P1173 [NOI2016]网格
    [NOI2018]归程
    宇宙旅行
    hdu 4027 Can you answer these queries?(线段树)
    poj 1661 Help Jimmy(记忆化搜索)
    hdu 1078 FatMouse and Cheese(简单记忆化搜索)
    poj 3616 Milking Time (基础dp)
    hdu 1074 Doing Homework(状压dp)
    codeforces 735C. Tennis Championship(贪心)
  • 原文地址:https://www.cnblogs.com/yongdaimi/p/6075198.html
Copyright © 2020-2023  润新知