ios - 如何在 Xamarin.iOS 中将 DetailTextLabel 垂直居中放置在 UITableView 的单元格中?

标签 ios uitableview xamarin.ios xamarin

实际上我想将 detailtextlabel 的位置设置为垂直居中。 在我的应用程序 detailtextlabel 位置根据单元格的 TextLabel(主要标签)。即它的对齐方式是右上角。

UITableViewCell cell = new UITableViewCell(UITableViewCellStyle.Value1, cellIdentifier); 
cell.TextLabel.LineBreakMode = UILineBreakMode.WordWrap; 
cell.TextLabel.Lines = 0; 
cell.TextLabel.Font = UIFont.PreferredCaption1; 
cell.Accessory = UITableViewCellAccessory.DisclosureIndicator; 
cell.TextLabel.Text = "some long text"; 
cell.DetailTextLabel.Text = childCount+"";

最佳答案

您将必须实现一个自定义表格单元格以使其按照您想要的方式进行布局。 TextLabelDetailTextTabel 是自动定位的,很难轻易改变它们的位置。

我建议使用 iOS 自动布局在 Storyboard中创建单元格以定位 View 。您将为单元定义一个自定义类,为新标签定义一个导出。您将使用这些 socket 而不是 iOS 提供的默认 TextLabelDetailsTextLabel 属性。

例如:

public UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
    var cell = tableView.DequeueReusableCell("YourCellID") as YourCell;
    cell.Update(passSomethingIn); //This public method would update your outlets
    return cell;
}

然后 YourCell 类将有一个 Update 方法来更改每一行的任何值。

关于ios - 如何在 Xamarin.iOS 中将 DetailTextLabel 垂直居中放置在 UITableView 的单元格中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26923888/

相关文章:

c# - Xamarin 内存分析器对象增长理解

ipad - 用MonoTouch(monodevelop)如何调试iPad?

iphone - iPhone 中的 GridView 问题

iphone - UISearchBar 在每次输入字母时调用 API,而不是在单击搜索按钮时调用 API

ios - 显示含有少量数据的单元格背景颜色

ios5 - 从 MonoTouch 访问 iCloud NSUbiquitousKeyValueStoreDidChangeExternallyNotification 详细信息

ios - 如果我在旋转设备 `insertRows` 时调用 "Incorrect checksum for freed object",UITableView 就会崩溃

android - 使用 react-native 启用电话设置

ios - 删除警告

iphone - 如何使 UITableView 可重排?