zoukankan      html  css  js  c++  java
  • 根据文字计算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;

  • 相关阅读:
    redis 基本指令
    php 魔术变量
    php 常用函数总结
    linux 命令——3 pwd (转)
    linux 命令——2 cd (转)
    linux 命令——ls
    ffmeg过滤器介绍[转]
    最简单的基于FFMPEG的转码程序 —— 分析
    ffmpga结构体和常用函数(总结)
    leetcode--3
  • 原文地址:https://www.cnblogs.com/chengfang/p/4175859.html
Copyright © 2011-2022 走看看