【问题标题】:Set Minimum Button Width in Xamarin Forms or iOS在 Xamarin 表单或 iOS 中设置最小按钮宽度
【发布时间】:2016-06-07 02:18:51
【问题描述】:

我们正在使用 Xamarin Forms 开发应用程序,但严重依赖于 iOS 的自定义渲染器,包括作为我们的按钮基类。我需要将应用程序中的所有按钮设置为最小宽度 120,但是似乎 MinimumWidthRequest 并没有实现这一点。如何设置按钮的最小宽度?

【问题讨论】:

    标签: xamarin.ios xamarin.forms


    【解决方案1】:

    试试这个替代方案

      var button = new Button();
            if (button.WidthRequest < 120)
            {
                button.WidthRequest = 120;
            }
    

    【讨论】:

    • 不幸的是,只有在设置了 WidthRequest 时才有效。如果它依赖于默认值,它将截断文本并将其设为 120(小于所需值)。我尝试检查 Width 而不是 WidthRequest,但遇到了同样的问题。
    • 此代码需要放入 SizeChanged 事件处理程序中,以便button.WidthRequest 获取值。
    猜你喜欢
    • 2017-03-16
    • 2015-07-30
    • 2021-11-07
    • 2023-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    相关资源
    最近更新 更多