IOS随记

作者: 梦之志 | 来源:发表于2016-10-08 10:21 被阅读0次

1.设置随机颜色

cell.backgroundColor = [UIColor colorWithRed:arc4random()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];

2.通过给定"字符内容" "字体大小" "View的宽度" 计算高度

#pragma mark- 通过内容动态计算高度

-(CGFloat)textHeight:(NSString *)string andFont:(UIFont *)fontSize andWith:(CGFloat)numSize{

    NSString * text = string;
    
    UIFont * font = fontSize;
    
    CGSize  size = CGSizeMake(numSize, MAXFLOAT);
    
    NSDictionary * dic = [NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName, nil];
    
    size = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading  attributes:dic context:nil].size;
    
    return size.height;

}

相关文章

网友评论

      本文标题:IOS随记

      本文链接:https://www.haomeiwen.com/subject/imduyttx.html