我为Xamarin.IOS应用程序创建了自己的自定义控件,并为其创建了自定义属性。我想在Visual Studio属性工具箱中为它的属性设置值,但是没有VS No 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)
{
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句