gpt4 book ai didi

ios - UITableViewCell 中的 UILabel - 切断信息

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:37:57 26 4
gpt4 key购买 nike

我正在开发一个 iOS 应用程序以在 UITableView 中显示有关我的 facebook 好友的信息,但我遇到了问题。我使用带有 2 个 UILable(字段和描述)的自定义单元格:

enter image description here

在字段标签中,我设置了教育、工作等信息的类别。在描述标签中,我设置了相应的信息:

enter image description here

我的问题是标签不适合信息的大小,并截掉了一部分,如上所示。我厌倦了寻找解决方案,但一无所获。我已经尝试实现此答案中的代码 ( Adjust UILabel height depending on the text ) 但无法正常工作!

有什么建议吗?谢谢

最佳答案

UILabels 很好,但你为什么不使用 UITextView ?你可以在 textView 中使用\n,我可以看到你在标签中有大文本,根据你的文本大小来缩放字体大小并不是一个很好的决定。只需将 textView 添加到您的自定义单元格,禁用用户交互,将 editable 设置为 NO,您就完成了。您还可以使用此代码根据文本大小更改单元格高度:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//Load text in NSString which you want in Cell's textView.
NSString *cellText;

cellText = @"Insert your text here";

//define font for textView...
UIFont *cellFont = [UIFont fontWithName:@"Georgia" size:19.0];//change your font here

CGSize constraintSize = CGSizeMake(330.0f, MAXFLOAT);

CGSize labelSize_val = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];

return labelSize_val.height + 20;
}

关于ios - UITableViewCell 中的 UILabel - 切断信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20587759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com