我有自己的自定义元素派生自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))
};
}
}
关于为什么截断细节线不起作用的任何想法?其他一切正常。我的默认值是尾部截断,但对于这个特定的视图,我想要中间截断。没有截断样式。
答案 0 :(得分:4)
我快速计算出来......当DetailLines属性设置为1时,它将截断。除非行号设置为1,否则使用AdjustsFontSizeToFitWidth
进行截断或文本大小调整不起作用。
如果在SO上存在类似的问题,我会删除这个问题,除非它被推翻(它可以帮助其他人)。