UItextView自定义其高度,禁止滚动

/*
 返回指定内容的textView控件高度
 value:指定的控件内容
 fontSize:指定的控件内容字号
 width:控件宽度
 */
- (float) heightForString:(NSString *_Nullable)value fontSize:(float)fontSize andWidth:(float)width{
    UITextView *detailTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, width, 0)];
    detailTextView.font = [UIFont systemFontOfSize:fontSize];
    detailTextView.text = value;
    CGSize deSize = [detailTextView sizeThatFits:CGSizeMake(width,CGFLOAT_MAX)];
    return deSize.height;
}

你可能感兴趣的:(iOS,Xcode,Object-c)