title: How to add show/hide password image in a Xamarin.Forms Editor for ios project. (scrolling and UI placement issues)
body: <p>I am trying to place a button to implement show/hide password in a custom <code>UITextView</code> in <strong>Xamarin.iOS</strong> (Editor in <strong>Xamarin.Forms</strong>). However I am facing two (2) issues with the UI design.</p>
  
  <p>I have used this code used for the show/hide password button setup, and it works perfectly:</p>
  
  <pre><code>UITextView vUpdatedEntry = (UITextView)Control;
  var buttonRect = UIButton.FromType(UIButtonType.Custom);
  buttonRect.SetImage(UIImage.FromBundle("show_black_24"), UIControlState.Normal);
  buttonRect.TouchUpInside += (object sender, EventArgs e1) =&gt; {
      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);
      }
  };
  </code></pre>
  
  <p><strong>Issue 1</strong>. I am unable to prevent the button from scrolling away when the <code>UITextView</code> scrolls. Whenever scrolling occurs, this happens: </p>
  
  <p><a href="https://i.stack.imgur.com/YtpQw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YtpQw.png" alt="Scrolling-issue"></a></p>
  
  <p>Basically the button scrolls along with the text which is not ideal. Any ideas on how to fix this would be much appreciated.</p>
  
  <p><strong>Issue 2</strong>. I am trying to get the button which allows the user to select whether they want the password to be visible or not to be on the <strong>right</strong> side of the <code>UITextView</code>. I have used the code below to do this.</p>
  
  <pre><code>buttonRect.Frame = new CoreGraphics.CGRect(10.0f, 0.0f, 15.0f, 15.0f);
  buttonRect.ContentMode = UIViewContentMode.ScaleToFill;
  buttonRect.BackgroundColor = UIColor.Orange;
  
  UIView paddingViewRight = new UIView(new System.Drawing.RectangleF(0.0f, 0.0f, 30.0f, 18.0f));
  paddingViewRight.BackgroundColor = UIColor.Purple;
  paddingViewRight.AddSubview(buttonRect);
  
  buttonRect.TranslatesAutoresizingMaskIntoConstraints = false;
  buttonRect.CenterYAnchor.ConstraintEqualTo(paddingViewRight.CenterYAnchor).Active = true;
  
  vUpdatedEntry.TextContainerInset = new UIEdgeInsets(8.0f, 0.0f, 8.0f, paddingViewRight.Frame.Width+5.0f);
  vUpdatedEntry.AddSubview(paddingViewRight);
  
  paddingViewRight.TranslatesAutoresizingMaskIntoConstraints = false;
  paddingViewRight.TrailingAnchor.ConstraintEqualTo(vUpdatedEntry.LayoutMarginsGuide.TrailingAnchor, 9.0f).Active = true;
  paddingViewRight.HeightAnchor.ConstraintEqualTo(vUpdatedEntry.HeightAnchor).Active = true;
  paddingViewRight.WidthAnchor.ConstraintEqualTo(buttonRect.WidthAnchor,1.0f, 0.0f).Active = true;
  
  Control.Layer.CornerRadius = 4;
  Control.Layer.BorderColor = new CoreGraphics.CGColor(255, 255, 255);
  Control.Layer.MasksToBounds = true;
  vUpdatedEntry.TextAlignment = UITextAlignment.Left;
  </code></pre>
  
  <p>and it gives me this: </p>
  
  <p><a href="https://i.stack.imgur.com/iEAgl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iEAgl.png" alt="My solution"></a></p>
  
  <p>This is my desired <strong>visual</strong> outcome, as it looks like the image below when the background colors are removed:</p>
  
  <p><a href="https://i.stack.imgur.com/7y9jh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7y9jh.png" alt="My solution-2"></a></p>
  
  <p>However, this solution feels rather <em>hacky</em> with lots of constants used in places where I would expect that using an <code>AutoLayout</code> anchor property should have worked. I tried using the <code>TrailingAnchor</code> property with <code>ConstraintEqualTo</code> to achieve this (<strong><em>this</em></strong> being stickiness to the right side of <code>UITextView</code>), but it kept sticking to the left-side instead. A cleaner approach to achieving this would be much appreciated</p>