public override void ViewDidLoad() { base.ViewDidLoad(); this.View.AutosizesSubviews = true; ImageView.Image = UIImageHelper.FromFileAuto("iTunesArtwork"); ImageView.Layer.CornerRadius = 24f; ImageView.Layer.MasksToBounds = true; CancelButton.SetBackgroundImage(Images.Buttons.GreyButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal); CancelButton.TintColor = UIColor.Black; CancelButton.Layer.ShadowColor = UIColor.Black.CGColor; CancelButton.Layer.ShadowOffset = new CGSize(0, 1); CancelButton.Layer.ShadowOpacity = 0.3f; CancelButton.TouchUpInside += (sender, e) => DismissViewController(true, OnDismissed); EnableButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal); EnableButton.TintColor = UIColor.White; EnableButton.Layer.ShadowColor = UIColor.Black.CGColor; EnableButton.Layer.ShadowOffset = new CGSize(0, 1); EnableButton.Layer.ShadowOpacity = 0.3f; EnableButton.TouchUpInside += EnablePushNotifications; PushLabel.Layer.CornerRadius = PushLabel.Frame.Width / 2; PushLabel.Layer.MasksToBounds = true; }
public override void ViewDidLoad() { base.ViewDidLoad(); ImageView.Image = UIImageHelper.FromFileAuto("iTunesArtwork"); CancelButton.SetBackgroundImage(Images.Buttons.GreyButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal); CancelButton.TintColor = UIColor.Black; CancelButton.Layer.ShadowColor = UIColor.Black.CGColor; CancelButton.Layer.ShadowOffset = new SizeF(0, 1); CancelButton.Layer.ShadowOpacity = 0.3f; CancelButton.TouchUpInside += (sender, e) => DismissViewController(true, OnDismissed); EnableButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal); EnableButton.TintColor = UIColor.White; EnableButton.Layer.ShadowColor = UIColor.Black.CGColor; EnableButton.Layer.ShadowOffset = new SizeF(0, 1); EnableButton.Layer.ShadowOpacity = 0.3f; EnableButton.TouchUpInside += EnablePushNotifications; var lbl = new UILabel(); lbl.Frame = new RectangleF(ImageView.Frame.Width - 25, -15, 40, 40); lbl.TextAlignment = UITextAlignment.Center; lbl.Layer.CornerRadius = lbl.Frame.Width / 2; lbl.Layer.MasksToBounds = true; lbl.BackgroundColor = UIColor.Red; lbl.Text = "12"; lbl.Font = UIFont.SystemFontOfSize(18f); lbl.TextColor = UIColor.White; ImageView.AddSubview(lbl); _hud = new Hud(View); }
public void SetDocumentDataAndImageSource(Image image) { if (Document == null) { return; } Document.DocumentData = ImageHelper.ConvertImageToByteArray(image, ImageFormatItem, ImageQuality.Value); Document.Size = Document.DocumentData != null ? Document.DocumentData.Length / 1024.0m / 1024.0m : 0; ImageSource = UIImageHelper.ConvertByteArrayImage(Document.DocumentData); }
public static UIColor CreateRepeatingBackground() { UIImage bgImage = null; if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { bgImage = UIImageHelper.FromFileAuto(MonoTouch.Utilities.IsTall ? "Default-568h" : "Default"); } else { if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown) { bgImage = UIImageHelper.FromFileAuto("Default-Portrait"); } else { bgImage = UIImageHelper.FromFileAuto("Default-Landscape"); } } if (bgImage == null) { return(null); } var size = new System.Drawing.SizeF(40f, bgImage.Size.Height); UIGraphics.BeginImageContext(size); var ctx = UIGraphics.GetCurrentContext(); ctx.TranslateCTM(0, bgImage.Size.Height); ctx.ScaleCTM(1f, -1f); ctx.DrawImage(new System.Drawing.RectangleF(-10, 0, bgImage.Size.Width, bgImage.Size.Height), bgImage.CGImage); ctx.ClipToRect(new System.Drawing.RectangleF(0, 0, size.Width, size.Height)); var img = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); bgImage.Dispose(); bgImage = null; if (img == null) { return(null); } var ret = UIColor.FromPatternImage(img); img.Dispose(); return(ret); }
public MarkdownComposerView(IAlertDialogService alertDialogService, IStatusIndicatorService statusIndicatorService) { _alertDialogService = alertDialogService; _statusIndicatorService = statusIndicatorService; _viewSegment = new UISegmentedControl(new [] { "Compose", "Preview" }); _viewSegment.SelectedSegment = 0; NavigationItem.TitleView = _viewSegment; _viewSegment.ValueChanged += SegmentValueChanged; var pictureImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/picture"); var linkImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/link"); var photoImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/photo"); var buttons = new [] { CreateAccessoryButton("@", () => TextView.InsertText("@")), CreateAccessoryButton("#", () => TextView.InsertText("#")), CreateAccessoryButton("*", () => TextView.InsertText("*")), CreateAccessoryButton("`", () => TextView.InsertText("`")), CreateAccessoryButton(pictureImage, () => { var range = TextView.SelectedRange; TextView.InsertText("![]()"); TextView.SelectedRange = new MonoTouch.Foundation.NSRange(range.Location + 4, 0); }), CreateAccessoryButton(photoImage, () => SelectImage()), CreateAccessoryButton(linkImage, () => { var range = TextView.SelectedRange; TextView.InsertText("[]()"); TextView.SelectedRange = new MonoTouch.Foundation.NSRange(range.Location + 1, 0); }), CreateAccessoryButton("~", () => TextView.InsertText("~")), CreateAccessoryButton("=", () => TextView.InsertText("=")), CreateAccessoryButton("-", () => TextView.InsertText("-")), CreateAccessoryButton("+", () => TextView.InsertText("+")), CreateAccessoryButton("_", () => TextView.InsertText("_")), CreateAccessoryButton("[", () => TextView.InsertText("[")), CreateAccessoryButton("]", () => TextView.InsertText("]")), CreateAccessoryButton("<", () => TextView.InsertText("<")), CreateAccessoryButton(">", () => TextView.InsertText(">")), }; SetAccesoryButtons(buttons); }
private static IEnumerable <UIButton> CreateButtons(UITextView controller) { var pictureImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/picture"); var linkImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/link"); var photoImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/photo"); var serviceConstructor = Locator.Current.GetService <IServiceConstructor>(); var vm = serviceConstructor.Construct <MarkdownAccessoryViewModel>(); return(new [] { CreateAccessoryButton("@", () => controller.InsertText("@")), CreateAccessoryButton("#", () => controller.InsertText("#")), CreateAccessoryButton("*", () => controller.InsertText("*")), CreateAccessoryButton("`", () => controller.InsertText("`")), CreateAccessoryButton(pictureImage, () => { var range = controller.SelectedRange; controller.InsertText("![]()"); controller.SelectedRange = new Foundation.NSRange(range.Location + 4, 0); }), CreateAccessoryButton(photoImage, () => vm.PostToImgurCommand.ExecuteAsync().Catch(Observable.Empty <string>()) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => controller.InsertText("![Image](" + x + ")"))), CreateAccessoryButton(linkImage, () => { var range = controller.SelectedRange; controller.InsertText("[]()"); controller.SelectedRange = new Foundation.NSRange(range.Location + 1, 0); }), CreateAccessoryButton("~", () => controller.InsertText("~")), CreateAccessoryButton("=", () => controller.InsertText("=")), CreateAccessoryButton("-", () => controller.InsertText("-")), CreateAccessoryButton("+", () => controller.InsertText("+")), CreateAccessoryButton("_", () => controller.InsertText("_")), CreateAccessoryButton("[", () => controller.InsertText("[")), CreateAccessoryButton("]", () => controller.InsertText("]")), CreateAccessoryButton("<", () => controller.InsertText("<")), CreateAccessoryButton(">", () => controller.InsertText(">")), }); }
public override void ViewDidLoad() { base.ViewDidLoad(); var pictureImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/picture"); var linkImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/link"); var photoImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/photo"); var buttons = new [] { CreateAccessoryButton("@", () => TextView.InsertText("@")), CreateAccessoryButton("#", () => TextView.InsertText("#")), CreateAccessoryButton("*", () => TextView.InsertText("*")), CreateAccessoryButton("`", () => TextView.InsertText("`")), CreateAccessoryButton(pictureImage, () => { var range = TextView.SelectedRange; TextView.InsertText("![]()"); TextView.SelectedRange = new MonoTouch.Foundation.NSRange(range.Location + 4, 0); }), CreateAccessoryButton(photoImage, SelectImage), CreateAccessoryButton(linkImage, () => { var range = TextView.SelectedRange; TextView.InsertText("[]()"); TextView.SelectedRange = new MonoTouch.Foundation.NSRange(range.Location + 1, 0); }), CreateAccessoryButton("~", () => TextView.InsertText("~")), CreateAccessoryButton("=", () => TextView.InsertText("=")), CreateAccessoryButton("-", () => TextView.InsertText("-")), CreateAccessoryButton("+", () => TextView.InsertText("+")), CreateAccessoryButton("_", () => TextView.InsertText("_")), CreateAccessoryButton("[", () => TextView.InsertText("[")), CreateAccessoryButton("]", () => TextView.InsertText("]")), CreateAccessoryButton("<", () => TextView.InsertText("<")), CreateAccessoryButton(">", () => TextView.InsertText(">")), }; SetAccesoryButtons(buttons); NavigationItem.RightBarButtonItem = new UIBarButtonItem("Save", UIBarButtonItemStyle.Done, (s, e) => ViewModel.SaveCommand.ExecuteIfCan()); NavigationItem.RightBarButtonItem.EnableIfExecutable(ViewModel.SaveCommand); }
public static UIImage LoadSplashImage() { UIImage bgImage = null; if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { bgImage = UIImageHelper.FromFileAuto(IsTall ? "Default-568h" : "Default"); } else { if (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.Portrait || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.PortraitUpsideDown) { bgImage = UIImageHelper.FromFileAuto("Default-Portrait"); } else { bgImage = UIImageHelper.FromFileAuto("Default-Landscape"); } } return(bgImage); }
private static IEnumerable <UIButton> CreateButtons(UITextView controller, IReactiveCommand <string> postImage) { var pictureImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/picture"); var linkImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/link"); var photoImage = UIImageHelper.FromFileAuto("Images/MarkdownComposer/photo"); return(new [] { CreateAccessoryButton("@", () => controller.InsertText("@")), CreateAccessoryButton("#", () => controller.InsertText("#")), CreateAccessoryButton("*", () => controller.InsertText("*")), CreateAccessoryButton("`", () => controller.InsertText("`")), CreateAccessoryButton(pictureImage, () => { var range = controller.SelectedRange; controller.InsertText("![]()"); controller.SelectedRange = new MonoTouch.Foundation.NSRange(range.Location + 4, 0); }), CreateAccessoryButton(photoImage, () => postImage.ExecuteAsync().Catch(Observable.Empty <string>()) .Subscribe(x => controller.InsertText("![Image](" + x + ")"))), CreateAccessoryButton(linkImage, () => { var range = controller.SelectedRange; controller.InsertText("[]()"); controller.SelectedRange = new MonoTouch.Foundation.NSRange(range.Location + 1, 0); }), CreateAccessoryButton("~", () => controller.InsertText("~")), CreateAccessoryButton("=", () => controller.InsertText("=")), CreateAccessoryButton("-", () => controller.InsertText("-")), CreateAccessoryButton("+", () => controller.InsertText("+")), CreateAccessoryButton("_", () => controller.InsertText("_")), CreateAccessoryButton("[", () => controller.InsertText("[")), CreateAccessoryButton("]", () => controller.InsertText("]")), CreateAccessoryButton("<", () => controller.InsertText("<")), CreateAccessoryButton(">", () => controller.InsertText(">")), }); }
protected override void Render() { ApplyVisibility(); // Foreground if (Brush.TryGetColorWithOpacity(Element.Foreground, out var foregroundColor)) { Native.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, }; } else { Native.TitleTextAttributes = null; } // Background var backgroundColor = Brush.GetColorWithOpacity(Element.Background); switch (backgroundColor) { case Color opaqueColor when opaqueColor.A == byte.MaxValue: // Prefer BarTintColor because it supports smooth transitions Native.BarTintColor = opaqueColor; Native.Translucent = false; //Make fully opaque for consistency with SetBackgroundImage Native.SetBackgroundImage(null, UIBarMetrics.Default); Native.ShadowImage = null; break; case Color semiTransparentColor when semiTransparentColor.A > 0: Native.BarTintColor = null; // Use SetBackgroundImage as hack to support semi-transparent background Native.SetBackgroundImage(((UIColor)semiTransparentColor).ToUIImage(), UIBarMetrics.Default); Native.Translucent = true; Native.ShadowImage = null; break; case Color transparent when transparent.A == 0: Native.BarTintColor = null; Native.SetBackgroundImage(new UIImage(), UIBarMetrics.Default); // We make sure a transparent bar doesn't cast a shadow. Native.ShadowImage = new UIImage(); // Removes the default 1px line Native.Translucent = true; break; default: //Background is null Native.BarTintColor = null; Native.SetBackgroundImage(null, UIBarMetrics.Default); // Restores the default blurry background Native.ShadowImage = null; // Restores the default 1px line Native.Translucent = true; break; } // CommandBarExtensions.BackButtonForeground var backButtonForeground = Brush.GetColorWithOpacity(Element.GetValue(BackButtonForegroundProperty) as Brush); Native.TintColor = backButtonForeground; // CommandBarExtensions.BackButtonIcon var backButtonIcon = Element.GetValue(BackButtonIconProperty) is BitmapIcon bitmapIcon ? UIImageHelper.FromUri(bitmapIcon.UriSource) : null; Native.BackIndicatorImage = backButtonIcon; Native.BackIndicatorTransitionMaskImage = backButtonIcon; if (Element.Presenter != null) { Element.Presenter.Height = Native.Hidden ? 0 : Native.Frame.Size.Height; } }
protected override void Render() { // Icon & Content if (Element.Icon != null) { switch (Element.Icon) { case BitmapIcon bitmap: Native.Image = UIImageHelper.FromUri(bitmap.UriSource); Native.CustomView = null; Native.Title = null; break; case FontIcon font: // not supported case PathIcon path: // not supported case SymbolIcon symbol: // not supported default: this.Log().WarnIfEnabled(() => $"{GetType().Name ?? "FontIcon, PathIcon and SymbolIcon"} are not supported. Use BitmapIcon instead with UriSource."); Native.Image = null; Native.CustomView = null; // iOS doesn't add the UIBarButtonItem to the native logical tree unless it has an Image or Title set. // We default to an empty string to ensure it is added. Native.Title = string.Empty; break; } } else { switch (Element.Content) { case string text: Native.Image = null; Native.CustomView = null; Native.Title = text; break; case FrameworkElement fe: var currentParent = Element.GetParent(); _appBarButtonWrapper.Child = Element; //Restore the original parent if any, as we // want the DataContext to flow properly from the // CommandBar. Element.SetParent(currentParent); Native.Image = null; Native.CustomView = fe.Visibility == Visibility.Visible ? _appBarButtonWrapper : null; // iOS doesn't add the UIBarButtonItem to the native logical tree unless it has an Image or Title set. // We default to an empty string to ensure it is added, in order to support late-bound Content. Native.Title = string.Empty; break; default: Native.Image = null; Native.CustomView = null; // iOS doesn't add the UIBarButtonItem to the native logical tree unless it has an Image or Title set. // We default to an empty string to ensure it is added. Native.Title = string.Empty; break; } } // Label Native.AccessibilityHint = Element.Label; Native.AccessibilityLabel = Element.Label; // Foreground if (Element.Foreground is SolidColorBrush foreground) { var color = (UIColor)foreground.Color as UIColor; var alpha = (nfloat)(foreground.Opacity * Element.Opacity); Native.TintColor = color.ColorWithAlpha(alpha); } else { Native.TintColor = default(UIColor); // TODO .Clear; } // IsEnabled Native.Enabled = Element.IsEnabled; // Background var backgroundColor = (Element.Background as SolidColorBrush)?.ColorWithOpacity; if (backgroundColor != null) { if (HasContent) { // Setup the background color when a custom content is set. _appBarButtonWrapper.BackgroundColor = backgroundColor; } else { var isTransparent = backgroundColor.Value.A == 0; var backgroundImage = isTransparent ? new UIImage() // Clears the background : ((UIColor)backgroundColor).ToUIImage(); // Applies the solid color; // We're using SetBackgroundImage instead of SetBackgroundColor // because it extends all the way up under the status bar. Native.SetBackgroundImage(backgroundImage, UIControlState.Normal, UIBarMetrics.Default); } } }
private static UIImage CreateTemplateFromAuto(string path) { return(UIImageHelper.FromFileAuto(path)); }
protected override void Render() { ApplyVisibility(); var appearance = new UINavigationBarAppearance(); // Background var backgroundColor = Brush.GetColorWithOpacity(Element.Background); switch (backgroundColor) { case { } opaqueColor when opaqueColor.A == byte.MaxValue: if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) { appearance.ConfigureWithOpaqueBackground(); appearance.BackgroundColor = opaqueColor; } else { // Prefer BarTintColor because it supports smooth transitions Native.BarTintColor = opaqueColor; Native.Translucent = false; //Make fully opaque for consistency with SetBackgroundImage Native.SetBackgroundImage(null, UIBarMetrics.Default); Native.ShadowImage = null; } break; case { } semiTransparentColor when semiTransparentColor.A > 0: if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) { appearance.ConfigureWithDefaultBackground(); appearance.BackgroundColor = semiTransparentColor; } else { Native.BarTintColor = null; // Use SetBackgroundImage as hack to support semi-transparent background Native.SetBackgroundImage(((UIColor)semiTransparentColor).ToUIImage(), UIBarMetrics.Default); Native.Translucent = true; Native.ShadowImage = null; } break; case { } transparent when transparent.A == 0: if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) { appearance.ConfigureWithTransparentBackground(); appearance.BackgroundColor = transparent; } else { Native.BarTintColor = null; Native.SetBackgroundImage(new UIImage(), UIBarMetrics.Default); // We make sure a transparent bar doesn't cast a shadow. Native.ShadowImage = new UIImage(); // Removes the default 1px line Native.Translucent = true; } break; default: //Background is null if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) { appearance.ConfigureWithDefaultBackground(); appearance.BackgroundColor = null; } else { Native.BarTintColor = null; Native.SetBackgroundImage(null, UIBarMetrics.Default); // Restores the default blurry background Native.ShadowImage = null; // Restores the default 1px line Native.Translucent = true; } break; } // Foreground if (Brush.TryGetColorWithOpacity(Element.Foreground, out var foregroundColor)) { if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) { appearance.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, }; appearance.LargeTitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, }; } else { Native.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, }; } } else { if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) { appearance.TitleTextAttributes = new UIStringAttributes(); appearance.LargeTitleTextAttributes = new UIStringAttributes(); } else { Native.TitleTextAttributes = null; } } // CommandBarExtensions.BackButtonForeground var backButtonForeground = Brush.GetColorWithOpacity(Element.GetValue(BackButtonForegroundProperty) as Brush); Native.TintColor = backButtonForeground; // CommandBarExtensions.BackButtonIcon var backButtonIcon = Element.GetValue(BackButtonIconProperty) is BitmapIcon bitmapIcon ? UIImageHelper.FromUri(bitmapIcon.UriSource)?.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal) : null; if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0)) { var backButtonAppearance = new UIBarButtonItemAppearance(UIBarButtonItemStyle.Plain); if (backButtonForeground is { } foreground) { var titleTextAttributes = new UIStringAttributes { ForegroundColor = foreground }; var attributes = new NSDictionary <NSString, NSObject>( new NSString[] { titleTextAttributes.Dictionary.Keys[0] as NSString }, titleTextAttributes.Dictionary.Values ); backButtonAppearance.Normal.TitleTextAttributes = attributes; backButtonAppearance.Highlighted.TitleTextAttributes = attributes; if (backButtonIcon is { } image) { var tintedImage = image.ApplyTintColor(foreground); appearance.SetBackIndicatorImage(tintedImage, tintedImage); } } else { if (backButtonIcon is { } image) { appearance.SetBackIndicatorImage(image, image); } } appearance.BackButtonAppearance = backButtonAppearance; }