Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios TableView中的标签宽度不会根据sizeToFit autolayout缩小_Ios_Objective C_Autolayout - Fatal编程技术网

Ios TableView中的标签宽度不会根据sizeToFit autolayout缩小

Ios TableView中的标签宽度不会根据sizeToFit autolayout缩小,ios,objective-c,autolayout,Ios,Objective C,Autolayout,我正在尝试使用表格创建聊天视图,但我的标签宽度没有响应其宽度 标签的约束 bubbleview的约束 代码 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ //...... some code here oLblMessage.text=chat.iText; [oLblMessage sizeToFit]

我正在尝试使用表格创建聊天视图,但我的标签宽度没有响应其宽度

标签的约束

bubbleview的约束

代码

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     //...... some code here
     oLblMessage.text=chat.iText;
     [oLblMessage sizeToFit]; // this doesn't responded at sll
     NSLog(@"%f",oLblMessage.frame.size.width);
     [oLblMessage layoutIfNeeded];
     [cell setNeedsUpdateConstraints];
     return cell;
}
结果

甚至我也尝试设置优先级,但没有成功。


因此,由于当前的限制,任何解决方案都不会根据文本大小设置其宽度。在标签中添加宽度约束,并使其小于或等于。在cellForRowAtIndexpath中,计算文本的大小,并通过其iboutlet将size.width指定给lableWidth contstraint常量。

如下所示设置约束

对于气泡:

对于标签:


也许这将帮助您..

删除固定宽度约束,为其提供前导和尾随等宽度约束而不是固定宽度约束只需将标签的前导约束更改为尾随。不,它不起作用。。。我确实试过让你移除那个宽度约束?它对我很有效,你必须应用一些约束逻辑,或者在标签中添加尾随约束,并将等宽约束更改为小于或等于。试一试,然后大小适合你应该有相同的图像为两个。请回答。谢谢@Idan的建议