gpt4 book ai didi

c# - 在 Xamarin iOS 中调整 UIView 大小

转载 作者:行者123 更新时间:2023-11-28 23:46:21 25 4
gpt4 key购买 nike

我想知道为什么我不能像通常在 Swift 中那样为 view.Frame 设置值。现在我正在使用 C# Xamarin 应用程序并尝试调整 UIView 的大小,但它没有响应它始终保持不变的任何方法。当我尝试更改 View.Frame 时

"Cannot modify the return value of 'UIView.Frame' because it is not a variable"

.我试图更改 UIView 的框架,使其适合屏幕,但此选项不起作用。如何更改适合所有屏幕的 UIView 框架?

        public void NotchNavBarCreator(UIView bar, UINavigationBar barItem) {
CGRect barfr = bar.Frame;
CGRect baritfr = barItem.Frame;
barfr.Width = this.View.Bounds.Width;
baritfr.Width = this.View.Bounds.Width;
bar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
}

最佳答案

您必须重新设置 Frame 变量,如下所示:

bar.Frame = new CGRect(x: 0, y: 0, width: 123, height: 321);

因此,如果您只想更改宽度,请执行以下操作:

//create a rect based on the old values + the new width value
barfr.Frame = new CGRect(x: barfr.Frame.X, y: barfr.Frame.Y, width: this.View.Bounds.Width, height: barfr.Frame.Height);

关于c# - 在 Xamarin iOS 中调整 UIView 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52589882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com