var okButton = UIAlertAction.Create (okText, UIAlertActionStyle.Default,null);
UIImage image = UIImage.FromBundle ("circle");
okButton.SetValueForKey (image, new NSString ("image"));
alertController.AddAction (okButton);
alertController.SetValueForKey (messageAttrite,new NSString("attributedMessage"));
var titleAttrite = new NSMutableAttributedString ("", UIFont.FromName ("GESSThree-Light", 17));
alertController.SetValueForKey (titleAttrite,new NSString("attributedTitle"));
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController (alertController, true, null);
方案二:自定義類,繼承UIAlertController
public class CustomAlertView:UIAlertController
{
public override void ViewWillAppear (bool animated)
{
R (this.View);
base.ViewWillAppear (animated);
}
private void R(UIView view)
{
foreach (var childView in view.Subviews)
{
if (childView is UIButton) {
((UIButton)childView).Font = UIFont.FromName ("GESSThree-Light", 15);
}
if (childView is UILabel) {
((UILabel)childView).Font = UIFont.FromName ("GESSThree-Light", 17);
}
if (childView.Subviews != null)
{
R (childView);
}
}
}
public override UIAlertControllerStyle PreferredStyle {
get {
return UIAlertControllerStyle.Alert;
}
}
}
使用:
var alertController =new CustomAlertView();
alertController.Message = messageText;
var okButton = UIAlertAction.Create (okText, UIAlertActionStyle.Default,null);
alertController.AddAction (okButton);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController (alertController, true, null);