I have my own custom element derived from StyledMultilineElement:
public class SubmenuElement : StyledMultilineElement
{
public static UITableViewCellStyle DefaultCellStyle { get; set; }
public static UITableViewCellAccessory DefaultCellAccessory { get; set; }
public static UILineBreakMode DefaultDetailTextLineBreakMode { get; set; }
public UILineBreakMode DetailTextLineBreakMode { get; set; }
public int? DetailLines { get; set; }
public bool? DetailTextResizesFontToFitWidth { get; set; }
static SubmenuElement()
{
// Set the defaults
DefaultCellStyle = UITableViewCellStyle.Default;
DefaultCellAccessory = UITableViewCellAccessory.DisclosureIndicator;
DefaultDetailTextLineBreakMode = UILineBreakMode.TailTruncation;
}
...
public override UITableViewCell GetCell (UITableView tv)
{
var cell = base.GetCell (tv);
if (cell.DetailTextLabel != null && !string.IsNullOrWhiteSpace(cell.DetailTextLabel.Text))
{
if (DetailLines.HasValue)
cell.DetailTextLabel.Lines = DetailLines.Value;
cell.DetailTextLabel.LineBreakMode = DetailTextLineBreakMode;
if (DetailTextResizesFontToFitWidth.HasValue)
cell.DetailTextLabel.AdjustsFontSizeToFitWidth = DetailTextResizesFontToFitWidth.Value;
}
return cell;
}
}
It seems that setting the LineBreakMode for DetailText has no effect.
public class PeopleView
{
....
void CreateUI()
{
var root = new RootElement(Header)
{
GroupAndSortResults(people, CurrentState.PeopleDirectoryOptions.GroupAndSort)
.Select (g => new Section(g.Key)
{
g.Select<PeopleListItem, SubmenuElement> (p => new SubmenuElement(
GetName (p),
p.TypeGradeSchool,
() => GoToPersonProfile(p.ID),
null,
UITableViewCellAccessory.None,
UITableViewCellStyle.Subtitle
)
{
ImageUri = PersonAvatarImage.GetAvatar (p.ID),
OnImageLoaded = WhenImageLoaded,
DetailTextLineBreakMode = UILineBreakMode.MiddleTruncation,
DetailTextResizesFontToFitWidth = true,
DetailLines = 0
}).ToArray ()
}).ToArray()
};
this.Root = root;
this.NavigationItem.RightBarButtonItems = new UIBarButtonItem[]
{
new UIBarButtonItem(UIBarButtonSystemItem.Organize, new EventHandler(WhenOrganizerTapped)),
new UIBarButtonItem(UIBarButtonSystemItem.Refresh, new EventHandler(WhenRefreshTapped))
};
}
}
Any ideas on why the truncation for detail lines doesn’t work? Everything else works properly. My default is tail truncation but for this specific view I wanted middle truncation. No truncation styles work.
I figured it out fast… It will truncate when the DetailLines property is set to 1. Truncation or text resizing using
AdjustsFontSizeToFitWidthdoesn’t work unless that lines number is set to 1.If there is a similar question to this one on SO, I will delete this question, unless it is upvoted (it helps someone else out).