【发布时间】:2015-12-04 05:00:40
【问题描述】:
我有一个字符串末尾没有空格,但是当我转换为NSAttributedString 并设置为UITextView 时,在UILabel 末尾看到了一些空格。
为了制作NSAttributedString,我正在使用以下代码。在我的代码中expectedLabelSize 给出了一个很大的高度。
UILabel *tempLbl = [[UILabel alloc]init];
tempLbl.font = txtView.font;
tempLbl.text = string;
NSDictionary *dictAttributes = [NSDictionary dictionaryWithObjectsAndKeys: tempLbl.font, NSFontAttributeName, aParaStyle, NSParagraphStyleAttributeName,[UIColor darkGrayColor],NSForegroundColorAttributeName, nil];
CGSize expectedLabelSize = [string boundingRectWithSize:maximumLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dictAttributes context: nil].size;
【问题讨论】:
-
用初始化
string的代码更新你的问题。为什么您的问题涉及UITextView?您发布的代码没有提及文本视图。UILabel和这个问题有什么关系?它与expectedLabelSize无关。 -
您是否尝试将
设置为 0,然后执行 sizeToFit ?
标签: ios objective-c whitespace nsattributedstring