我在我的 UITableViewSource
中使用填充来格式化单元格。我有:
//cell declared somewhere in `UITableViewSource`
var name = rows[indexPath.Row].MachineName.PadRight(50);
我也试过这个:
var name = rows[indexPath.Row].MachineName.PadRight(50, ' ');
我有一些设置单元格文本:
cell.TextLabel.Text = "01234567"+ ""+ name + "01234567";
输出如下:
01234567 SomeNameHere 01234567
-------------------------------------------
01234567 SomeNameHere 01234567
--------------------------------------------
01234567 SomeOtherNameHere 01234567
--------------------------------------------
01234567 ShortName 01234567
---------------------------------------------
我已经检查了 name
的长度,它们都是 50,但是当它在我的设备上显示在单元格中时,它并没有对齐。 Xamarin、iOS、UITableViewCell
有什么特别之处吗?可能有所不同。
我的解决方法是使用 XCode 创建一个 UITableViewCell,但如果这可行就太好了。
最佳答案
尝试:
var name = rows[indexPath.Row].MachineName.PadRight(10, '\t');
关于c# - 字符串填充不占用相同的字符间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22615003/