ios - Xamarin IOS 自定义控件属性不显示
问题描述
我为我的 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)
{
}
推荐阅读
- java - 在java中初始化返回nulll后访问方法外的值
- python - 使用 C++ 在 TSV 中读取后 PyImport_Import 分段错误
- ansible - 如何使用 Ansible 自动接受适用于 unix 的 MS ODBC 的 EULA?
- api - 您可以仅通过 API 测试使用 Paypal 付款(没有界面)吗?
- java - Java - 如何将 ArrayList 输入拆分为日期和字符串,然后进行比较?
- angular - 从管道图中的 HttpResponse.body 检索数据时出错
- r - R中的周期性模式识别
- webpack - 有没有办法解析 webpack 的输出而不在文件开头添加字节顺序标记(BOM)?
- java - 如何在准备好的语句中转义单引号。?
- rest - 如何从邮递员向 elasticsearch 发送条件 GET 方法?