使用iOS自定义渲染器,有没有一种方法可以让问号项出现在TextCell中并打开一个对话框?

时间:2017-08-09 20:37:06

标签: c# xamarin xamarin.forms

我有这个XAML

<TableSection Title="Application">
   <TextCell x:Name="appUpdated" Text="Updated" />
   <TextCell x:Name="appVersion" Text="Application Version" />
</TableSection>

这个C#:

public InfoPage()
{
   InitializeComponent();
   appUpdated.Text = AS.appUpdated;
   appVersion.Text = AS.appVersion;
}

有没有办法让我可以在文本的右边显示一个小问号并点击它打开一个带有解释的对话框?

请注意我正在寻找带有自定义渲染器的iOS解决方案。我之前找到了一些关于此的参考文献,但不能再找到例子了。

1 个答案:

答案 0 :(得分:1)

请参阅此sample

还需要 ViewCellRenderer 并稍加改动。

  • NativeiOSCell 中的 CellImageView UIImageView 替换为 UIButton ,因为我们需要点击事件到打开一个对话框并显示信息。

  • 添加按钮点击事件以显示其他信息

    CellImageView = new UIButton();
    CellImageView.TouchUpInside += delegate
    {
        UIAlertView alert = new UIAlertView()
        {
            Title = HeadingLabel.Text,
            Message = SubheadingLabel.Text
        };
        alert.AddButton("OK");
        alert.Show();
    };
    
  • 修改按钮获取图像的方式

    CellImageView.SetBackgroundImage(GetImage(cell.ImageFilename),UIControlState.Normal);
    
  • 调整文字和图片的框架。

    public override void LayoutSubviews()
    {
        base.LayoutSubviews();
        HeadingLabel.Frame = new CGRect(5, 4, ContentView.Bounds.Width - 63, 25);
        CellImageView.Frame = new CGRect(ContentView.Bounds.Width - 63, 5, 33, 33);
    }
    

这是我的考试。 enter image description here

PS:如果您仍然对我的回答有任何疑惑,我会尝试在github上传一个演示。