我需要显示一条警告,其中部分消息以斜体显示,另一部分正常,如下所示:
var title = "Title";
var body = "This part in Italic. This part normal.";
Application.Current.MainPage.DisplayAlert(title, body, "OK");
部分说:"这部分用斜体字。"斜体和正常文本中的另一个。
有可能吗?如果是,怎么样?
提前致谢!
答案 0 :(得分:1)
我最终创建了一个像这样的原生警报控制器:
void PromptRichTextPopup(string title, string richMessage, string normalMessage, Action onOkCallback, Action onCancel = null) {
var vc = UIKit.UIApplication.SharedApplication.KeyWindow.RootViewController;
// take top presented view controller
while (vc.PresentedViewController != null) {
vc = vc.PresentedViewController;
}
var alertvc = UIAlertController.Create(title, string.Empty, UIAlertControllerStyle.Alert);
var leftAligned = new NSMutableParagraphStyle();
leftAligned.Alignment = UITextAlignment.Left;
var colorTitle = new NSAttributedString(str: title, font: UIFont.BoldSystemFontOfSize(18), foregroundColor: Xamarin.Forms.Color.FromHex("#61acad").ToUIColor());
alertvc.SetValueForKey(colorTitle, new NSString("attributedTitle"));
var margin = 5f;
var height = 30f;
var width = 256f;
var container = new UIView(new CGRect(margin, margin, width, height * 4));
var message = new NSMutableAttributedString(str: richMessage, font: UIFont.ItalicSystemFontOfSize(14), foregroundColor: UIColor.Black);
message.Append(new NSMutableAttributedString(str: " " + normalMessage, font: UIFont.SystemFontOfSize(14), foregroundColor: UIColor.Black));
var lblText = new UILabel(new CGRect(0, -(height / 2), width, height * 2)) { AttributedText = message };
lblText.LineBreakMode = UILineBreakMode.WordWrap;
lblText.Lines = 0;
container.AddSubview(lblText);
var cancel = new UIButton(new CGRect(0, height, width / 2, height * 2));
cancel.SetTitle("NO", UIControlState.Normal);
cancel.AddTarget((sender, e) => alertvc.DismissViewController(true, null), UIControlEvent.TouchUpInside);
cancel.SetTitleColor(UIColor.Blue, UIControlState.Normal);
if (onCancel != null) {
cancel.AddTarget((sender, e) => {
onCancel();
},
UIControlEvent.TouchUpInside);
}
container.AddSubview(cancel);
var ok = new UIButton(new CGRect(width / 2, height, width / 2, height * 2));
ok.SetTitle("YES", UIControlState.Normal);
Action okAction = async () => {
ok.Enabled = false;
await uiHelper.RunBlocking(() => {
onOkCallback();
});
alertvc.DismissViewController(true, null);
};
ok.SetTitleColor(UIColor.Blue, UIControlState.Normal);
container.AddSubview(ok);
ok.AddTarget((sender, e) => {
okAction();
}, UIControlEvent.TouchUpInside);
var controller = new UIViewController();
controller.View.AddSubview(container);
alertvc.SetValueForKey(controller, new NSString("contentViewController"));
vc.PresentViewController(alertvc, true, null);
}
答案 1 :(得分:0)
您可以尝试使用自定义渲染器来实现(使用自定义视图和渲染器来处理弹出窗口)但boost/multiprecision/cpp_bin_float.hpp
警报传达与状态有关的重要信息 您的应用或设备,并经常请求反馈。警报包括 标题,可选消息,一个或多个按钮和可选项 用于收集输入的文本字段。除了这些可配置 元素,警报的视觉外观是静态的,不可能 定制
it is not recommended by iOS可能对您有所帮助。