gpt4 book ai didi

c# - 字符串填充不占用相同的字符间距

转载 作者:行者123 更新时间:2023-11-29 03:07:23 24 4
gpt4 key购买 nike

我在我的 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/

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