首页 > 解决方案 > xamarin iOS 中的 MakeTextWritingDirectionRightToLeft(null)

问题描述

我正在尝试RightToLeft在我的项目中实现方向。其他工作正常,但标签没有在 iOS 中向右移动,为此我创建了一个LabelRenderer在其中传递此方法MakeTextWritingDirectionRightToLeft(null)但出现异常的方法

Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[UILabel makeTextWritingDirectionRightToLeft:]: unrecognized selector sent to instance 0x7fd2fb68b680

谁能告诉我在这个函数的参数中传递什么而不是null?

标签: xamarinxamarin.ios

解决方案


您可以尝试使用以下代码在我的项目中实现 RightToLeft 方向。

[assembly: ExportRenderer(typeof(Label), typeof(CustomLabel))]
public class CustomLabel: LabelRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
        {
            base.OnElementChanged(e);
            Control.TextAlignment = UITextAlignment.Right;
            
        }
    }

推荐阅读