无法为 UIButton
setImage
。
当使用 Image 设置 backgroundColor
时,我想将它的显示图像设置为“backButton.png”
当 setImage 为 UIButton
时,它根本不显示
backButton.SetImage (UIImage.FromFile ("/Images/backButton.png"), UIControlState.Normal);
我想将 setImage 设置为 UIButton
。
//下面是代码
UIButton backButton = UIButton.FromType(UIButtonType.Custom);
backButton.Frame = new RectangleF (5, 5, 45, 30);
backButton.BackgroundColor = UIColor.FromPatternImage (UIImage.FromBundle ("/Images/backButton.png"));
backButton.SetImage (UIImage.FromFile ("/Images/backButton.png"), UIControlState.Normal);
backButton.TouchUpInside += (sender, ea) => {
this.NavigationController.PopViewControllerAnimated(true);
};
最佳答案
我对 Xamarin
了解不多。但 xcode 项目中呈现的目录结构与实际不同(应用程序编译后)。
所有文件和资源都位于名为 main bundle 的同一目录中.
要访问您的资源,您只需从主包中请求即可。您不必指定 xcode 项目导航器的目录(资源所在的目录)。
您可以阅读更多 directory structure here
关于c# - 无法在 Xamarin C# 中将图像设置为 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25008971/