【问题标题】:Font Size change KerningAdjustment, why?字体大小改变 KerningAdjustment,为什么?
【发布时间】:2019-09-26 11:54:52
【问题描述】:

我解决了这个问题,我创建了一个函数,我只需传递我需要的间距值和 TextField

public static void ChangeSpaceBetweenCharacters(this UITextField textField, float space)
{
   textField.WeakDefaultTextAttributes.SetValueForKey(NSObject.FromObject((nfloat)space), UIStringAttributeKey.KerningAdjustment);

}

最好的问候, 拉斐尔·桑托斯

【问题讨论】:

    标签: c# swift xamarin.ios kerning


    【解决方案1】:

    我认为问题可能是由您使用的字体方法引起的,我无法使其工作:

     UIFont("ArialMT", 13)
    

    相反,您可以使用:

     Font = UIFont.FromName("ArialMT", 13),
    

    或者

     Font = UIFont.SystemFontOfSize(10),
    

    我测试了下面的示例代码,它对我有用:

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        // Perform any additional setup after loading the view, typically from a nib.
    
        NSMutableAttributedString mtText = new NSMutableAttributedString("testTextfield", new UIStringAttributes
        {
            Font = UIFont.SystemFontOfSize(10),
            KerningAdjustment = 8.0f
    
        });
    
        UITextField textField = new UITextField();
        textField.Frame = new CoreGraphics.CGRect(10,20,350,50);
        textField.AttributedText = mtText;        
    
        Add(textField);
    
    }
    

    【讨论】:

    • 感谢您的帮助,但我认为这是 VS for Mac 和 Xcode 之间的通信问题。我找到的解决方案是更改 Xcode 中的字体,所以它已经可以工作了。不过还是谢谢。
    猜你喜欢
    • 2021-12-20
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 2012-03-04
    • 2019-12-17
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    相关资源
    最近更新 更多