【问题标题】:Xamarin.Forms - Image not showing in ImageButton on iOSXamarin.Forms - 图像未显示在 iOS 上的 ImageButton 中
【发布时间】:2014-11-13 05:39:07
【问题描述】:

我一直无法在我的 iOS 应用程序的 Xamarin.Forms 中的 ImageButton 中显示图像。按钮功能正常且可单击,但文本和图像源未正确显示。相反,有一个可点击的蓝色框,并以省略号作为文本值。 (http://i.imgur.com/kdQtOL0.png) 我将图像放在 Resources 文件夹中,并将构建操作设置为 BundleResource。我还可以将图像显示为简单的图像(而不是按钮),因此我知道 iOS 可以看到文件夹中的图像。我正在使用以下格式向我的页面添加按钮。

Grid btns = SetUpGrid(1, 0, 0, 0, false);

var ib = new ImageButton();
ib.Image = "account.png";
ib.Text = "Account";
ib.HorizontalOptions = LayoutOptions.Start;
ib.VerticalOptions = LayoutOptions.FillAndExpand;
ib.Clicked += Home_BillClicked;
btns.Children.Add(ib, 0, 1);
Grid.SetColumnSpan(ib, 2);

图像在 WP8 和 Android 应用程序中都能完美显示和运行。 iOS 似乎是唯一一个在渲染 ImageButton 时出现问题的设备。有谁知道是什么原因造成的?

【问题讨论】:

  • Xamarin.Forms 控件集中没有 ImageButton
  • 您使用的是 xForm.labs dll,以及 xamarin 的版本

标签: ios xamarin.ios xamarin xamarin.forms


【解决方案1】:

改为 ib.Image = "account.png",改为 ib.Source = "account.png";并添加到您的 AppDelegate 类继承自 XFormsApplicationDelegate。

【讨论】:

    猜你喜欢
    • 2019-02-17
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多