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;

  • 相关阅读:
    c# 动态加载工具栏按钮代码
    根据结果集处理工作事务c#源码
    关于升级后药库中报表需要重新设置的问题
    vs2005打开工程后退出
    把照片写入到DataTable
    关于导入最新住院管理后界面控件乱的问题
    django实战2运维日常维护统计
    ip_conntrack_netbios_n 报错
    django_book学习笔记7django常用方法总结
    python模块整理14re模版
  • 原文地址:https://www.cnblogs.com/chengfang/p/4175859.html
Copyright © 2011-2022 走看看