Created
February 4, 2019 23:08
-
-
Save rdelrosario/34a54cb0d13b9e68cd3d7fac4fe5b3d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.ComponentModel; | |
using CoreGraphics; | |
using Foundation; | |
using KeyboardOptionsSample; | |
using KeyboardOptionsSample.iOS; | |
using UIKit; | |
using Xamarin.Forms; | |
using Xamarin.Forms.Platform.iOS; | |
[assembly: ExportRenderer(typeof(CustomEditor), typeof(CustomEditorRenderer))] | |
namespace KeyboardOptionsSample.iOS | |
{ | |
public class CustomEditorRenderer : EditorRenderer | |
{ | |
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e) | |
{ | |
base.OnElementChanged(e); | |
if (Control == null && Element == null) return; | |
var element = Element as CustomEditor; | |
if (element.HasExtraOptions) | |
{ | |
Control.InputAccessoryView = new UIView(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 42)) | |
{ | |
BackgroundColor = UIColor.White | |
}; | |
var line = new UIView(new CGRect(0, 0, Control.InputAccessoryView.Frame.Width, 1)); | |
line.BackgroundColor = UIColor.LightGray; | |
var btn1 = new UIButton(new CGRect(0, 1, 160, 41)); | |
btn1.SetTitle("Attach media", UIControlState.Normal); | |
btn1.SetTitleColor(UIColor.Blue, UIControlState.Normal); | |
btn1.TitleEdgeInsets = new UIEdgeInsets(0, 20, 0, 0); | |
btn1.Font = UIFont.BoldSystemFontOfSize(15f); | |
btn1.SetImage(UIImage.FromFile("GalleryIcon.png"), UIControlState.Normal); | |
btn1.SetTitleColor(UIColor.FromRGB(78, 101, 202), UIControlState.Normal); | |
btn1.TouchUpInside += element.OnAttachMediaEvent; | |
var btn2 = new UIButton(new CGRect(Control.InputAccessoryView.Frame.Width - 160, 1, 160, 41)); | |
btn2.SetTitle("Take a photo", UIControlState.Normal); | |
btn2.TitleEdgeInsets = new UIEdgeInsets(0, 0, 0, 20); | |
btn2.Font = UIFont.BoldSystemFontOfSize(15f); | |
btn2.SemanticContentAttribute = UISemanticContentAttribute.ForceRightToLeft; | |
btn2.SetImage(UIImage.FromFile("CameraIcon.png"), UIControlState.Normal); | |
btn2.SetTitleColor(UIColor.Blue, UIControlState.Normal); | |
btn2.SetTitleColor(UIColor.FromRGB(78, 101, 202), UIControlState.Normal); | |
btn2.TouchUpInside += element.OnTakePhotoEventEvent; | |
Control.InputAccessoryView.Add(line); | |
Control.InputAccessoryView.Add(btn1); | |
Control.InputAccessoryView.Add(btn2); | |
Control.InputAccessoryView.AutoresizingMask = UIViewAutoresizing.All; | |
Control.ReturnKeyType = UIReturnKeyType.Send; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment