• 根据文字计算label的宽度和高度


    // 滚动条中的描述文字

            UILabel *desLabel = (UILabel *)[appCell.mAppDescription viewWithTag:101];

       desLabel.numberOfLine = 0;

            desLabel.text = _appDetailModel.mDescription;

            NSLog(@"desLabel.text = %@", desLabel.text);

            

            UIFont *font = [UIFont fontWithName:@"Arial" size:10];//跟label的字体大小一样

            CGSize size = CGSizeMake(300, 29999);//跟label的宽设置一样

            

            NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];

            size =[desLabel.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:dic context:nil].size;

            appCell.mAppDescription.contentSize = size;

    ************************************************************************************************************************

    // 徽章不隐藏

            self.hidden = NO;

            // 设置提醒文字

            [self setTitle:badgeValue forState:UIControlStateNormal];

            // 设置frame

            CGRect frame = self.frame;

            CGFloat BadgeH = self.currentBackgroundImage.size.height;

            CGFloat badgeW = self.currentBackgroundImage.size.width;

            // 消息数 > 9(超过一位数)

            if (badgeValue.length > 1)

            {

                CGSize badgeSize = [badgeValue sizeWithAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"Arial" size:11]}];

    //            CGSize badgeSize = [badgeValue sizeWithFont:self.titleLabel.font];

                badgeW = badgeSize.width + 10;

            }

            frame.size.width = badgeW;

            frame.size.height = BadgeH;

  • 相关阅读:
    CentOs7-替换下载源
    CentOs7-常用命令
    Django Nginx+uwsgi 安装配置
    Linux操作系统下文件作用
    U盘创建macOS安装盘
    国内开源镜像站点汇总
    gcd常见用法
    mac rvm 升级 ruby 安装cocoapod 指定版本
    confluence 搭建 wiki 并破解
    homebrew 安装 java 指定版本
  • 原文地址:https://www.cnblogs.com/chengfang/p/4175859.html
Copyright © 2020-2023  润新知