protected override void OnAttached() { formsEditor = Element as EditorWithPlaceholder; nativeTextField = Control as UITextView; placeholderText = new UILabel { LineBreakMode = UILineBreakMode.WordWrap, Lines = 1, BackgroundColor = UIColor.Clear, TextColor = formsEditor.PlaceholderTextColor.ToUIColor(), Text = formsEditor.Placeholder }; if (string.IsNullOrEmpty(formsEditor.Text)) { placeholderText.Alpha = 1; } else { placeholderText.Alpha = 0; } nativeTextField.AddSubview(placeholderText); }
protected override void OnAttached() { _textView = Control as UITextView; _placeholderLabel = new UILabel(); _placeholderLabel.LineBreakMode = UILineBreakMode.WordWrap; _placeholderLabel.Lines = 0; _placeholderLabel.Font = _textView.Font; _placeholderLabel.BackgroundColor = UIColor.Clear; _placeholderLabel.Alpha = 0; UpdateText(); UpdateColor(); _textView.AddSubview(_placeholderLabel); _placeholderLabel.TranslatesAutoresizingMaskIntoConstraints = false; _placeholderLabel.TopAnchor.ConstraintEqualTo(_textView.TopAnchor, 8).Active = true; _placeholderLabel.LeftAnchor.ConstraintEqualTo(_textView.LeftAnchor, 4).Active = true; _placeholderLabel.RightAnchor.ConstraintEqualTo(_textView.RightAnchor, 4).Active = true; _placeholderLabel.WidthAnchor.ConstraintEqualTo(_textView.WidthAnchor, 1, -8).Active = true; _textView.SendSubviewToBack(_placeholderLabel); if (_textView.Text.Length == 0 && _placeholderLabel.Text.Length > 0) { _placeholderLabel.Alpha = 1; } _textView.Changed += _textView_Changed; }
private void CreatePlaceholderLabel(PlaceholderEditor element, UITextView parent) { _placeholderLabel = new UILabel { Text = element.Placeholder, TextColor = element.PlaceholderColor.ToUIColor(), BackgroundColor = UIColor.Clear, //Font = UIFont.FromName(element.FontFamily, (nfloat)element.FontSize) }; if (!string.IsNullOrEmpty(element.FontFamily)) { _placeholderLabel.Font = UIFont.FromName(element.FontFamily, (nfloat)element.FontSize); } else { _placeholderLabel.Font = UIFont.SystemFontOfSize((nfloat)element.FontSize); } _placeholderLabel.SizeToFit(); parent.AddSubview(_placeholderLabel); parent.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints(); parent.AddConstraints( _placeholderLabel.AtLeftOf(parent, 7), _placeholderLabel.AtTopOf(parent, 8) ); parent.LayoutIfNeeded(); _placeholderLabel.Hidden = parent.HasText; }
private void SetPlaceholder() { var _titleTextViewDelegate = new PostTitleTextViewDelegate(); titleTextField.Delegate = _titleTextViewDelegate; _titleTextViewDelegate.EditingStartedAction += () => { Activeview = titleTextField; }; titlePlaceholderLabel = new UILabel(); titlePlaceholderLabel.Text = "Enter a title of your photo"; titlePlaceholderLabel.SizeToFit(); titlePlaceholderLabel.Font = Constants.Regular14; titlePlaceholderLabel.TextColor = Constants.R151G155B158; titlePlaceholderLabel.Hidden = false; var labelX = titleTextField.TextContainerInset.Left; var labelY = titleTextField.TextContainerInset.Top; var labelWidth = titlePlaceholderLabel.Frame.Width; var labelHeight = titlePlaceholderLabel.Frame.Height; titlePlaceholderLabel.Frame = new CGRect(5, labelY, labelWidth, labelHeight); titleTextField.AddSubview(titlePlaceholderLabel); _titleTextViewDelegate.Placeholder = titlePlaceholderLabel; var _descriptionTextViewDelegate = new PostTitleTextViewDelegate(2048); _descriptionTextViewDelegate.EditingStartedAction += () => { Activeview = descriptionTextField; }; descriptionTextField.Delegate = _descriptionTextViewDelegate; descriptionPlaceholderLabel = new UILabel(); descriptionPlaceholderLabel.Text = "Enter a description of your photo"; descriptionPlaceholderLabel.SizeToFit(); descriptionPlaceholderLabel.Font = Constants.Regular14; descriptionPlaceholderLabel.TextColor = Constants.R151G155B158; descriptionPlaceholderLabel.Hidden = false; var descLabelX = descriptionTextField.TextContainerInset.Left; var descLabelY = descriptionTextField.TextContainerInset.Top; var descLabelWidth = descriptionPlaceholderLabel.Frame.Width; var descLabelHeight = descriptionPlaceholderLabel.Frame.Height; descriptionPlaceholderLabel.Frame = new CGRect(5, descLabelY, descLabelWidth, descLabelHeight); descriptionTextField.AddSubview(descriptionPlaceholderLabel); _descriptionTextViewDelegate.Placeholder = descriptionPlaceholderLabel; _descriptionTextViewDelegate.EditingStartedAction += EditingStartedAction; _titleTextViewDelegate.EditingStartedAction += EditingStartedAction; }
private void CreatePlaceholderLabel(EditorWithPlaceholder element, UITextView parent) { placeholderLabel = new UILabel { Text = element.Placeholder, TextColor = element.PlaceholderColor.ToUIColor(), BackgroundColor = UIColor.Clear, TextAlignment = UITextAlignment.Natural }; placeholderLabel.SizeToFit(); parent.AddSubview(placeholderLabel); parent.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints(); parent.AddConstraints(placeholderLabel.AtLeftOf(parent, 7), placeholderLabel.WithSameCenterY(parent)); parent.LayoutIfNeeded(); placeholderLabel.Hidden = parent.HasText; }
private void SetPlaceholder() { var placeholderLabel = new UILabel(); placeholderLabel.Text = AppSettings.LocalizationManager.GetText(LocalizationKeys.PutYourComment); placeholderLabel.SizeToFit(); placeholderLabel.Font = Constants.Regular14; placeholderLabel.TextColor = Constants.R151G155B158; placeholderLabel.Hidden = false; var labelX = _commentTextView.TextContainerInset.Left; var labelY = _commentTextView.TextContainerInset.Top; var labelWidth = placeholderLabel.Frame.Width; var labelHeight = placeholderLabel.Frame.Height; placeholderLabel.Frame = new CGRect(labelX, labelY, labelWidth, labelHeight); _commentTextView.AddSubview(placeholderLabel); _commentsTextViewDelegate.Placeholder = placeholderLabel; }
private void CreatePlaceholderLabel(PlaceholderEditor element, UITextView parent) { _placeholderLabel = new UILabel { Text = element.Placeholder, TextColor = element.PlaceholderColor.ToUIColor(), BackgroundColor = UIColor.Clear, Font = UIFont.FromName(element.FontFamily, (nfloat)element.FontSize) }; _placeholderLabel.SizeToFit(); parent.AddSubview(_placeholderLabel); parent.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints(); parent.AddConstraints( _placeholderLabel.AtLeftOf(parent, 7), _placeholderLabel.WithSameCenterY(parent) ); parent.LayoutIfNeeded(); _placeholderLabel.Hidden = parent.HasText; }
private void ConfigureControl() { if (Control != null) { if (Control is UITextView) { UITextView vUpdatedEntry = (UITextView)Control; this.UiTextViewForControl = vUpdatedEntry; var buttonRect = UIButton.FromType(UIButtonType.Custom); buttonRect.SetImage(UIImage.FromBundle("show_black_24"), UIControlState.Normal); buttonRect.TouchUpInside += (object sender, EventArgs e1) => { if (vUpdatedEntry.SecureTextEntry) { vUpdatedEntry.SecureTextEntry = false; buttonRect.SetImage(UIImage.FromBundle("hide_black_24"), UIControlState.Normal); } else { vUpdatedEntry.SecureTextEntry = true; buttonRect.SetImage(UIImage.FromBundle("show_black_24"), UIControlState.Normal); } // Change the text based on whether password is to be hidden or visible. HandleSecureEntryChange(vUpdatedEntry); }; vUpdatedEntry.ShouldChangeText += (textView, range, toReplaceText) => { if ("\n" == toReplaceText) { //Drop the keyboard if 'Enter/Return' is pressed vUpdatedEntry.ResignFirstResponder(); return(false); } //Get the text that was entered, store that in LastText. Return true, so that Changed is called. LastText = new NSString(toReplaceText); return(true); }; // Add eventHandler for Changed. vUpdatedEntry.Changed += HandleTextChange; buttonRect.ContentMode = UIViewContentMode.ScaleToFill; UIView paddingViewRight = new UIView(new System.Drawing.RectangleF(0.0f, 0.0f, 30.0f, 18.0f)); paddingViewRight.AddSubview(buttonRect); buttonRect.TranslatesAutoresizingMaskIntoConstraints = false; buttonRect.CenterYAnchor.ConstraintEqualTo(paddingViewRight.CenterYAnchor).Active = true; vUpdatedEntry.AddSubview(paddingViewRight); paddingViewRight.TranslatesAutoresizingMaskIntoConstraints = false; paddingViewRight.TrailingAnchor.ConstraintEqualTo(vUpdatedEntry.LayoutMarginsGuide.TrailingAnchor, 8.0f).Active = true; paddingViewRight.HeightAnchor.ConstraintEqualTo(vUpdatedEntry.HeightAnchor).Active = true; paddingViewRight.BottomAnchor.ConstraintEqualTo(vUpdatedEntry.LayoutMarginsGuide.BottomAnchor).Active = true; paddingViewRight.TopAnchor.ConstraintEqualTo(vUpdatedEntry.LayoutMarginsGuide.TopAnchor, -8.0f).Active = true; paddingViewRight.WidthAnchor.ConstraintEqualTo(buttonRect.WidthAnchor, 1.0f, 3.0f).Active = true; vUpdatedEntry.TextContainerInset = new UIEdgeInsets(8.0f, 0.0f, 8.0f, paddingViewRight.Frame.Width + 5.0f); Control.Layer.CornerRadius = 4; Control.Layer.BorderColor = new CoreGraphics.CGColor(255, 255, 255); Control.Layer.MasksToBounds = true; vUpdatedEntry.TextAlignment = UITextAlignment.Left; } } }