I am using padding in my UITableViewSource to format a cell. I have:

//cell declared somewhere in `UITableViewSource`

var name = rows[indexPath.Row].MachineName.PadRight(50);

I have tried this as well:

var name = rows[indexPath.Row].MachineName.PadRight(50, ' ');

I have some set the cell text:

cell.TextLabel.Text = "01234567" + " " + name + "01234567";

The output looks like:

01234567 SomeNameHere           01234567
-------------------------------------------
01234567 SomeNameHere           01234567
--------------------------------------------
01234567 SomeOtherNameHere         01234567
--------------------------------------------
01234567 ShortName            01234567
---------------------------------------------

I have checked the length of name and all of them are 50 but when its shown on my device in the cell it doesn't line up. Is there something special with Xamarin, iOS, UITableViewCell - something that may be different.

My work around for this would be to create a UITableViewCell using XCode but it would be nice if this could work.

有帮助吗?

解决方案 2

I ended up using a monospaced font as suggested by @Jason and it seems Courier New is the only one available in iOS just from my quick search.

其他提示

Try:

var name = rows[indexPath.Row].MachineName.PadRight(10, '\t');
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top