Xamarin.iOS - Action Sheet Line Numbers

2019-08-20 06:15发布

问题:

I have this scenario: My action sheets have a variant text size, like in this question, but trying to access this API from xamarin iOS, I cant find the property:

UILabel.appearance(whenContainedInInstancesOf: [UIAlertController.self]).numberOfLines = 2

Reading this question, anwsered by @SushiHangover, there are many hidden API's by Xamarin, and with the code, I think I can achieve the desired behavior.

So, in Xamarin.iOS, how can I force my action sheet's options to have two or more lines of text? I'm not familiar with iOS internals or Objective-C.

I tried to found the Attribute name of this property and try the Sushi's solution, but with no luck.

回答1:

I found a solution:

Using SushiHangover's solution on his answer, i can achieve the desired behavior using the following code:

var styleHandle = IosUtils.GetAppearanceEx(Class.GetHandle("UILabel"), typeof(UIAlertController));
        IosUtils.void_objc_msgSend_IntPtr(styleHandle, Selector.GetHandle("setNumberOfLines:"), ((NSNumber)2).Handle);

I can't affirm if is the best solution, but I can do what I need.