UIAlertController 自定义字体不起作用。
下面的代码是一个函数ShowActionSheetAsync
, show ActionSheet
。
此时我想改变字体ActionSheet
。我尝试了多种方法,但效果并不好。有好的解决办法吗?
public Task<bool> ShowActionSheetAsync()
{
var source = new TaskCompletionSource<bool>();
var alert = new UIAlertController
{
Title = "title"
};
alert.AddAction(UIAlertAction.Create(
"button1",
UIAlertActionStyle.Default,
_ => source.SetResult(true)));
alert.AddAction(UIAlertAction.Create(
"cancel",
UIAlertActionStyle.Cancel,
_ => source.SetResult(false)));
// [Block 1]
var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
ViewController.PresentViewController(alert, true, delegate
{
// [Block 2]
});
// [Block 3]
return source.Task;
}
第一次尝试以下代码无法正常工作。
UILabel.AppearanceWhenContainedIn(typeof(UIActionSheet)).Font
= UIFont.FromName(StyleResources.MediumFontName, 20);
第二次尝试下面的代码也无法正常工作。
-
当我把代码放在[Block 2]
-
当我把代码放在[Block 3]
FindDescendantViews<UILabel>()
是一个扩展方法UIView
并返回适当类型的所有子视图。
var labels = alert.View.FindDescendantViews<UILabel>();
foreach (var label in labels)
{
label.Font = UIFont.FromName(StyleResources.MediumFontName, 20);
}