首先,我使用的是 Xamarin iOS。
每当我尝试设置 UIButton 的图像时,图像就会变得与整个屏幕一样大。我希望该图像适合 UIButton 的边界/框架。
我尝试过使用 PDF 图像和 PNG 图像(屏幕截图中的图像是 png)。它们都忽略了它们嵌入的实际 UIButton 的框架和大小。
这是 UIButton 在 xcode 故事板中的外观。它与超级视图的垂直和水平中间对齐,宽度为超级视图的 0.25 倍,长宽比为 1:1。我也尝试给它一个固定的高度和宽度,但这没有帮助。
我调试了框架大小,但发现它保持不变并且不受 UIButtons 图像的影响。
总结一下我迄今为止尝试过但不起作用的一切:
public partial class ViewController : UIViewController
{
public ViewController(IntPtr handle) : base(handle)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// SetImage -> makes image as big as the screen
Btn.SetImage(UIImage.FromBundle("skip"), UIControlState.Normal);
// SetBackgroundImage -> Image doesn't appear at all, maybe I'm forgetting something?
Btn.SetBackgroundImage(UIImage.FromBundle("skip"), UIControlState.Normal);
// none of these things do …Run Code Online (Sandbox Code Playgroud)