简体   繁体   中英

How to put DetailTextLabel vertically center in cell of UITableView in Xamarin.iOS?

Actually i would like to set the position of detailtextlabel vertically center. In my app detailtextlabel position goes to according to TextLabel(main lable) of cell. ie it's allignment is top-right.

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+"";

You will have to implement a custom table cell to get it to layout how you want. TextLabel and DetailTextTabel are automatically positioned, and it's hard to change their position easily.

I would recommend creating the cell in your storyboard using iOS auto-layout to position your views. You would define a custom class for the cell, and outlets for the new labels. You would use these outlets instead of the default TextLabel and DetailsTextLabel properties that iOS provides.

So, for example:

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;
}

Then the YourCell class would have an Update method to change any values for each row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM