我有自己的从 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;
}
}
似乎为 DetailText 设置 LineBreakMode 没有效果。
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))
};
}
}
关于为什么截断细节行不起作用的任何想法?其他一切正常。我的默认设置是尾部截断,但对于这个特定的视图,我想要中间截断。没有截断样式有效。