gpt4 book ai didi

ios - Xamarin IOS 自定义控件属性不显示

转载 作者:行者123 更新时间:2023-11-28 17:31:12 26 4
gpt4 key购买 nike

我为 Xamarin.IOS 应用程序创建了自己的自定义控件,并为其创建了自定义属性。我想在 Visual Studio 属性工具箱中为其属性设置值,但没有 VS 没有 Xcode 不显示任何自定义属性。我必须为自定义按钮设置自定义文本紧排间距,我不想使用任何棘手或丑陋的方法来解决它。

这是我的自定义控件代码:

[Register("CustomButton"), DesignTimeVisible(true)]
public class CustomButton : UIButton
{
private float _textLetterSpacing;

protected internal CustomButton(IntPtr handle) : base(handle)
{
}

[Export("TextLetterSpacing"), Browsable(true)]
public float TextLetterSpacing
{
get => _textLetterSpacing;
set
{
_textLetterSpacing = value;
SetNeedsDisplay();
}
}

public CustomButton()
{
Initialize();

}

public override void AwakeFromNib()
{
// Called when loaded from xib or storyboard.
Initialize();
}

void Initialize()
{

TextLetterSpacing = -0.49f;
var title = this.Title(UIControlState.Normal);
var attributedTitle = new NSAttributedString(title, new UIStringAttributes() { KerningAdjustment = TextLetterSpacing, ForegroundColor = this.CurrentTitleColor });
this.SetAttributedTitle(attributedTitle, UIControlState.Normal);
SetNeedsDisplay();
}

}

最佳答案

我想通了这个问题。应该有 public 构造函数而不是 protected internal:

public CustomButton(IntPtr handle) : base(handle)
{
}

关于ios - Xamarin IOS 自定义控件属性不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52465290/

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