【发布时间】:2015-02-09 03:15:15
【问题描述】:
我已经使用以下问题的解决方案来填充 NSString Padding NSString not working,但是在将此字符串添加到 UITableViewCell 后,单元格标签没有正确填充
这是我用于填充的代码
cell.textLabel.text = [NSString stringWithFormat:@"%@%@", [question stringByPaddingToLength:50
withString:@" "
startingAtIndex:0], answer];
这是我在控制台上打印单元格文本时得到的结果
(lldb) po cell.textLabel.text
Where was the NTD PSU installed 5
(lldb) po cell.textLabel.text
Estimate of cable run distance. 5
(lldb) po cell.textLabel.text
Uploaded Picture of NTD PSU Location. No
但这是我在表格单元格中得到的内容
知道为什么会有差异吗?
【问题讨论】:
-
控制台使用等宽字体(每个字符具有相同的像素宽度),而单元格内的标签使用各种 Helvetica。你是如何计算这个填充的?
-
@oltman 我已经编辑了问题以添加我使用的代码,现在我如何将字体插入到方程式中?
-
@oltman 我认为您的回答是一个很好的解决方法
标签: ios objective-c uitableview nsstring padding