Ios 调整UILabel(UITableViewCell的子视图)中的文本大小以适应宽度
我有一个自定义的Ios 调整UILabel(UITableViewCell的子视图)中的文本大小以适应宽度,ios,uitableview,Ios,Uitableview,我有一个自定义的UITableViewCell,有时候,UILabel中的文本(UILabel是UITableViewCell中的子视图)超过了大小,它在标签中得到了一些点(如…)。 我想调整字体大小以适应宽度。但它不起作用 这是我的代码 UITableviewCell的类内实现 -(void) awakeFromNib{ myLabel.minimumFontSize = 8; myLabel.adjustsFontSizeToFitWidth = YES; } 请帮帮我 试
UITableViewCell
,有时候,UILabel
中的文本(UILabel
是UITableViewCell
中的子视图)超过了大小,它在标签中得到了一些点(如…)。
我想调整字体大小以适应宽度。但它不起作用
这是我的代码
UITableviewCell的类内实现
-(void) awakeFromNib{
myLabel.minimumFontSize = 8;
myLabel.adjustsFontSizeToFitWidth = YES;
}
请帮帮我 试试这个
myLabel.numberOfLines=0;
[myLabel sizeToFit];
试试这个简单的代码
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
label.backgroundColor=[UIColor clearColor];
label.text= yourString;
label.numberOfLines=0;
label.adjustsFontSizeToFitWidth=YES;
label.minimumFontSize=6;
label.textAlignment=UITextAlignmentCenter;
[self.View addSubview:label];
CGFloat fontSize = 20;
while (fontSize > 0.0)
{
CGSize size = [yourString sizeWithFont:[UIFont fontWithName:@"Rockwell-Bold" size:fontSize] constrainedToSize:CGSizeMake(label.frame.size.width, 10000) lineBreakMode:UILineBreakModeWordWrap];
if (size.height <= label.frame.size.height) break;
fontSize -= 1.0;
}
//set font size
label.font = [UIFont fontWithName:@"Rockwell-Bold" size:fontSize];
[label release];
UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(0,0,100,100)];
label.backgroundColor=[UIColor clearColor];
label.text=yourString;
label.numberOfLines=0;
label.adjustsFontSizeToFitWidth=是;
标签。最小字体大小=6;
label.textAlignment=UITextAlignmentCenter;
[self.View addSubview:label];
CgFontSize=20;
而(字体大小>0.0)
{
CGSize size=[yourString sizeWithFont:[UIFont fontWithName:@“Rockwell Bold”大小:fontSize]约束大小:CGSizeMake(label.frame.size.width,10000)lineBreakMode:UILineBreakModeWordWrap];
如果(size.height。首先,在TableViewClass
中,在heightForRowAtIndexPath
中,您必须根据标签计算文本的高度
,然后返回它。
并使标签的自动布局属性具有灵活的高度
。您不需要重置标签的框架
。试试看,它会起作用的。…我不清楚您的问题是什么,但是,您没有设置最小比例因子吗?