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

时间:2014-11-14 06:02:27

标签: 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+"";

1 个答案:

答案 0 :(得分:1)

您必须实现一个自定义表格单元格,以便根据需要进行布局。 TextLabelDetailTextTabel会自动定位,并且很难轻易改变其位置。

我建议您使用iOS自动布局在故事板中创建单元格以定位视图。您可以为单元格定义自定义类,为新标签定义出口。您可以使用这些商店而不是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方法来更改每行的任何值。