2

我有自己的从 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))
        };
    }

}

关于为什么截断细节行不起作用的任何想法?其他一切正常。我的默认设置是尾部截断,但对于这个特定的视图,我想要中间截断。没有截断样式有效。

4

1 回答 1

4

我很快就想通了...当 DetailLines 属性设置为 1 时,它将被截断。AdjustsFontSizeToFitWidth除非将行号设置为 1,否则使用截断或调整文本大小不起作用。

如果在 SO 上有与此问题类似的问题,我将删除此问题,除非它被赞成(它可以帮助其他人)。

于 2012-05-08T15:22:32.130 回答