Xamarin.iOS - Action Sheet Line Numbers

人走茶凉 提交于 2019-12-13 03:15:30

问题


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.



来源:https://stackoverflow.com/questions/52258352/xamarin-ios-action-sheet-line-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!