/// <summary> /// /// </summary> /// <param name="views">A list of views to display in the alert.</param> /// <param name="accentColor">Color of the circle.</param> /// <param name="title"></param> /// <param name="titleFont"></param> /// <param name="content"></param> /// <param name="contentFont"></param> /// <param name="alertType"></param> /// <param name="customImage">Image to be displayed in the circle.</param> /// <returns></returns> public static async Task ShowCustomAlert(List <View> views, Color accentColor, string title = "", ExtendedFont titleFont = null, string content = "", ExtendedFont contentFont = null, AlertType alertType = AlertType.AccentOnly, ImageSource customImage = null) { var view = new AdvancedAlertView(views, accentColor, title, titleFont, content, contentFont, alertType, customImage); await Application.Current.MainPage.Navigation.PushPopupAsync(view); }
public static NSMutableAttributedString BuildAttributedString(this ExtendedFont font, string text, UITextAlignment textAlignment = UITextAlignment.Natural) { if (font == null) { return(new NSMutableAttributedString(text)); } var attributes = new UIStringAttributes(); attributes.Font = font.ToUIFont(); attributes.ForegroundColor = font.Color.ToUIColor(); attributes.BackgroundColor = UIColor.Clear; attributes.KerningAdjustment = font.Kerning; if (font.IsUnderlined) { attributes.UnderlineStyle = NSUnderlineStyle.Single; } var attribString = new NSMutableAttributedString(text, attributes); if (font.LineSpacing != 0) { var paragraphStyle = new NSMutableParagraphStyle() { LineSpacing = (nfloat)font.LineSpacing, Alignment = textAlignment }; attribString.AddAttribute(UIStringAttributeKey.ParagraphStyle, paragraphStyle, new NSRange(0, attribString.Length)); } return(attribString); }
private static UIBarButtonItem[] SetCustomFontsToToolBars( List <Tuple <ToolbarItem, UIBarButtonItem> > navigationBarItems, ExtendedFont toolbarFont, bool visible = true) { var barItems = new List <UIBarButtonItem>(); navigationBarItems.ForEach(tuple => { var nativeItem = tuple.Item2; if (toolbarFont != null && !string.IsNullOrEmpty(tuple.Item2.Title)) { var button = new UIButton(); button.SetAttributedTitle(toolbarFont.BuildAttributedString(tuple.Item2.Title), UIControlState.Normal); button.TintColor = toolbarFont.Color.ToUIColor(); button.TitleLabel.SizeToFit(); button.Hidden = !visible; if (tuple.Item1 != null) { button.TouchUpInside += (sender, e) => ((IMenuItemController)tuple.Item1).Activate(); } button.SizeToFit(); nativeItem.CustomView = button; } barItems.Add(nativeItem); }); return(barItems.ToArray()); }
/// <summary> /// Adds individual action buttons to the alert view. /// </summary> /// <param name="action">Action.</param> public void AddAction(AdvancedActionSheetAction action) { var ExtendedButton = new ExtendedButton() { Style = AdvancedActionSheetStyles.StandardButtonStyle, Command = new Command(async() => { await Navigation.PopPopupAsync(); action.Command?.Execute(null); }), CustomFont = action.Font, Text = action.Title }; if (action.ActionType == ActionType.Cancel) { CancelButtonVisible = true; CancelText = action.Title; CancelFont = action.Font; CancelCommand = new Command(() => { action.Command?.Execute(null); }); OnPropertyChanged(nameof(CancelButtonVisible)); OnPropertyChanged(nameof(CancelCommand)); OnPropertyChanged(nameof(CancelText)); OnPropertyChanged(nameof(CancelFont)); } else { buttonStack.Children.Add(ExtendedButton); } }
/// <summary> /// Creates the action for the action sheet. /// </summary> /// <param name="title">Title.</param> /// <param name="font">Font.</param> /// <param name="command">Command.</param> /// <param name="type">Type of the action.</param> public static AdvancedActionSheetAction CreateAction(string title, ExtendedFont font, Command command, ActionType type = ActionType.Default) { return(new AdvancedActionSheetAction() { Title = title, Font = font, Command = command, ActionType = type }); }
/// <summary> /// Initializes a new instance of this <c>AdvancedAlertView</c> class. /// </summary> /// <param name="buttons">Buttons.</param> /// <param name="accentColor">Color of the circle.</param> /// <param name="title">Title.</param> /// <param name="titleFont">Title's font.</param> /// <param name="content">Content.</param> /// <param name="contentFont">Content's font.</param> /// <param name="alertType">Alert type.</param> /// <param name="customImage">Image to be displayed in the circle.</param> /// <param name="presetType">Preset type of the alert.</param> public AdvancedAlertView(List <View> buttons, Color accentColor, string title = "", ExtendedFont titleFont = null, string content = "", ExtendedFont contentFont = null, AlertType alertType = AlertType.AccentOnly, ImageSource customImage = null, PresetType presetType = PresetType.Positive) { _alertType = alertType; _presetType = presetType; BindingContext = this; HasSystemPadding = false; CloseWhenBackgroundIsClicked = false; CustomImageSource = customImage; AccentColor = accentColor; Animation = new AdvancedAlertViewAnimation(); InitializeComponent(); switch (alertType) { case AlertType.Preset: AddImage(false); break; case AlertType.Waiting: AddSpinner(); break; case AlertType.CustomImageAndAccent: AddImage(true); break; } if (buttons != null && buttons.Count > 0) { buttons.ForEach(AddButton); } TitleString = title; ContentString = content; TitleFont = titleFont; ContentFont = contentFont; SetRelativeLayoutConstraints(); OnPropertyChanged(nameof(TitleString)); OnPropertyChanged(nameof(ContentString)); OnPropertyChanged(nameof(TitleFont)); OnPropertyChanged(nameof(ContentFont)); OnPropertyChanged(nameof(AccentColor)); OnPropertyChanged(nameof(CustomImageSource)); }
/// <summary> /// /// </summary> /// <param name="accentColor"></param> /// <param name="title"></param> /// <param name="titleFont"></param> /// <param name="content"></param> /// <param name="contentFont"></param> /// <param name="duration">How long the alert should be visible</param> /// <returns></returns> public static async Task ShowWaitingAlert(Color accentColor, string title = "", ExtendedFont titleFont = null, string content = "", ExtendedFont contentFont = null, int duration = 0) { var view = new AdvancedAlertView(null, accentColor, title, titleFont, content, contentFont, AlertType.Waiting); await Application.Current.MainPage.Navigation.PushPopupAsync(view); if (duration > 0) { await Task.Delay(duration); await view.Navigation.PopPopupAsync(); } }
/// <summary> /// Displays a toast-style banner view. /// </summary> /// <returns>Returns a <see cref="Task"/> that displays the toast view.</returns> /// <param name="title">Title.</param> /// <param name="titlefont">Titlefont.</param> /// <param name="image">Image.</param> /// <param name="backgroundColor">Background color.</param> /// <param name="navigation">Navigation.</param> /// <param name="position">Position.</param> public static async Task DisplayToast(string title, ExtendedFont titlefont, ImageSource image, Color backgroundColor, INavigation navigation, BannerPosition position = BannerPosition.Top) { var view = new BannerView() { Text = title, TitleFont = titlefont, Image = image, Color = backgroundColor, Position = position }; await navigation.PushPopupAsync(view); await Task.Delay(2000); await navigation.PopPopupAsync(); }
/// <summary> /// Creates the button for the alert view. /// </summary> /// <returns>An <c>AdvancedAlertViewButton</c>.</returns> /// <param name="text">Text.</param> /// <param name="font">Font.</param> /// <param name="backgroundColor">Background color.</param> /// <param name="command">Command.</param> public static AdvancedAlertViewButton CreateButton(string text, ExtendedFont font, Color backgroundColor, Command command = null) { var button = new AdvancedAlertViewButton() { Text = text, CustomFont = font, BackgroundColor = backgroundColor }; if (command != null) { button.Command = command; } return(button); }
/// <summary> /// Initializes a new instance of this <c>AdvancedActionSheet</c> class. /// </summary> /// <param name="actions">Action buttons.</param> /// <param name="title">Title.</param> /// <param name="titleFont">Title font.</param> public AdvancedActionSheet(List <AdvancedActionSheetAction> actions, string title = "", ExtendedFont titleFont = null) { BindingContext = this; Actions = actions; TitleText = title; TitleFont = titleFont; Animation = new AdvancedActionSheetAnimation(); HasSystemPadding = false; CloseWhenBackgroundIsClicked = true; InitializeComponent(); CreateButtons(); }
public static void ApplyTo(this ExtendedFont font, TextView textView) { if (font == null) { return; } if (font.Family == null) { TypefaceStyle typefaceStyle = TypefaceStyle.Normal; switch (font.FontAttributes) { case FontAttributes.Bold: typefaceStyle = TypefaceStyle.Bold; break; case FontAttributes.Italic: typefaceStyle = TypefaceStyle.Italic; break; } textView.SetTypeface(Typeface.Default, typefaceStyle); } else { textView.SetTypeface(TypefaceHelper.GetTypeface(font.Family), TypefaceStyle.Normal); } textView.SetTextColor(font.Color.ToAndroid()); textView.SetTextSize(Android.Util.ComplexUnitType.Dip, font.Size); if (font.IsUnderlined) { SpannableString content = new SpannableString(textView.Text); content.SetSpan(new UnderlineSpan(), 0, textView.Text.Length, 0); textView.TextFormatted = content; } if (font.LineSpacing != 0) { textView.SetLineSpacing(font.LineSpacing, 1); } }
private static UIBarButtonItem[] SetCustomFontsToToolBars( List <UIBarButtonItem> navigationBarItems, ExtendedFont toolbarFont) { navigationBarItems.ForEach(nativeItem => { if (toolbarFont != null) { var textAttributes = new UITextAttributes() { Font = toolbarFont.ToUIFont(), TextColor = toolbarFont.Color.ToUIColor(), }; nativeItem.SetTitleTextAttributes(textAttributes, UIControlState.Normal); nativeItem.TintColor = toolbarFont.Color.ToUIColor(); } }); return(navigationBarItems.ToArray()); }
public CustomTypefaceSpan(ExtendedFont font) : base(font.Family) { _typeface = TypefaceHelper.GetTypeface(font.Family); }
/// <summary> /// Shows the advanced action sheet. /// </summary> /// <returns>Returns a <see cref="Task"/> that shows the action sheet.</returns> /// <param name="actions">Action buttons.</param> /// <param name="title">Title.</param> /// <param name="titleFont">Title font.</param> public static async Task ShowActionSheet(List <AdvancedActionSheetAction> actions, string title = "", ExtendedFont titleFont = null) { var view = new AdvancedActionSheet(actions, title, titleFont); await Application.Current.MainPage.Navigation.PushPopupAsync(view); }
public static UIFont ToUIFont(this ExtendedFont font) { if (font.Family == null) { switch (font.FontAttributes) { case FontAttributes.Bold: return(UIFont.BoldSystemFontOfSize(font.Size)); case FontAttributes.Italic: return(UIFont.ItalicSystemFontOfSize(font.Size)); case FontAttributes.None: return(UIFont.SystemFontOfSize(font.Size)); } } else { if (font.IsAccessibilityFont) { UIFontTextStyle textStyle = UIFontTextStyle.Body; switch (font.AccessibilityTextStyle) { case AccessibilityTextStyle.Callout: { textStyle = UIFontTextStyle.Callout; break; } case AccessibilityTextStyle.Caption1: { textStyle = UIFontTextStyle.Caption1; break; } case AccessibilityTextStyle.Caption2: { textStyle = UIFontTextStyle.Caption2; break; } case AccessibilityTextStyle.Footnote: { textStyle = UIFontTextStyle.Footnote; break; } case AccessibilityTextStyle.Headline: { textStyle = UIFontTextStyle.Headline; break; } case AccessibilityTextStyle.Subheadline: { textStyle = UIFontTextStyle.Subheadline; break; } case AccessibilityTextStyle.Title1: { textStyle = UIFontTextStyle.Title1; break; } case AccessibilityTextStyle.Title2: { textStyle = UIFontTextStyle.Title2; break; } case AccessibilityTextStyle.Title3: { textStyle = UIFontTextStyle.Title3; break; } } var uiFont = UIFont.GetPreferredFontForTextStyle(textStyle); return(UIFont.FromName(font.Family, uiFont.PointSize)); } else { return(UIFont.FromName(font.Family, font.Size)); } } return(UIFont.SystemFontOfSize(font.Size)); }
/// <summary> /// Initializes a new instance of this <c>FloatingLabelEntryNativeView</c> class. /// </summary> /// <param name="frame">Frame to display the floating label.</param> /// <param name="floatingLabelCustomFont">Floating label custom font.</param> public FloatingLabelEntryNativeView(CGRect frame, ExtendedFont floatingLabelCustomFont) : base(frame) { CustomFont = floatingLabelCustomFont; InitializeLabel(); }
/// <summary> /// /// </summary> /// <param name="buttons">A list of buttons to appear in the alert view.</param> /// <param name="presetType"></param> /// <param name="title"></param> /// <param name="titleFont"></param> /// <param name="content"></param> /// <param name="contentFont"></param> /// <param name="buttonFont"></param> /// <param name="okCommand"></param> /// <returns></returns> public static async Task ShowPresetAlert(List <ExtendedButton> buttons, PresetType presetType, string title = "", ExtendedFont titleFont = null, string content = "", ExtendedFont contentFont = null, ExtendedFont buttonFont = null, Command okCommand = null) { var view = new AdvancedAlertView(buttons.Cast <View>().ToList(), DefaultColor, title, titleFont, content, contentFont, AlertType.Preset, presetType: presetType); await Application.Current.MainPage.Navigation.PushPopupAsync(view); }