該
我曾嘗試使用 PDF 影像和 PNG 影像(螢屏截圖中的影像是 png)。它們都忽略了它們嵌入的實際 UIButton 的框架和大小。
這是 UIButton 在 xcode 故事板中的外觀。它與父視圖的垂直和水平中間對齊,寬度為父視圖的 0.25 倍,縱橫比為 1:1。我也嘗試給它一個固定的高度和寬度,但這沒有幫助。

我除錯了幀大小,但發現它保持不變并且不受 UIButtons Image 的影響。
總結一下我到目前為止嘗試過但不起作用的所有內容:
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 literally anything
Btn.ContentMode = UIViewContentMode.ScaleAspectFill;
Btn.ContentMode = UIViewContentMode.ScaleAspectFit;
Btn.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;
Btn.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit;
// also have no impact on the image at all
Btn.ImageEdgeInsets = new UIEdgeInsets(100, 100, 100, 100);
Btn.ContentEdgeInsets = new UIEdgeInsets(100, 100, 100, 100);
// also does nothing
UIImage image = UIImage.FromBundle("skip");
image.CreateResizableImage(new UIEdgeInsets(10, 10, 10, 10));
Btn.SetImage(image, UIControlState.Normal);
// no luck again
image.Scale(new CGSize(Btn.Frame.Width, Btn.Frame.Height), 0.1f);
Btn.SetImage(image, UIControlState.Normal);
}
}
我在模擬器上測驗的所有設備(iPhone 11、IPhone 12、IPhone 12 mini、iPod touch)上都存在這個問題。我還不能在真實設備上測驗它。
互聯網上似乎沒有其他人有這個問題。我錯過了什么?這可能是微不足道的,但我無法弄清楚。

到“默認”:

現在您的影像將適合受約束的按鈕大小。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/369970.html
標籤:C# ios 代码 xamarin.ios 按钮
上一篇:無法在表格單元格中呈現d3圖表
