iOS 设置UILable字体,及计算长度和位置

    UILabel *lastLable = [[UILabel alloc] init];
    UIFont *font = [UIFont fontWithName:lastLable.font.fontName size:[UIFont labelFontSize]-3];
    lastLable.font = font;


/**
 *  获取指定字体的字符串的长度
 *
 *  @param str  字符串
 *  @param font 字符串的字体
 *
 *  @return 字符串的长度
 */
-(double)getWidthWithString:(NSString*)str font:(UIFont*)font{
    NSDictionary *dict = @{NSFontAttributeName:font};
    CGSize detailSize = [str sizeWithAttributes:dict];
    return detailSize.width;
}

 

posted on 2015-12-16 05:50  大木哥  阅读(786)  评论(0编辑  收藏  举报

导航