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语言II作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    C语言ll作业01
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
  • 原文地址:https://www.cnblogs.com/chengfang/p/4175859.html
Copyright © 2011-2022 走看看