0

I am using an entry control of Xamarin.Forms for the iOS and Mac platforms. The problem I have is that I can control the horizontal alignment but not the vertical. I want to vertically center the text in the entry control but I am not able to do so.

I haven't found any solution for Xamarin but I did find a few links in Swift or Objective-C. So, I converted this code to C# and it doesn't work.

The below code is in the Mac renderer for my entry:

 var newRect =new CGRect(x: 0, y: 15, width: 30, height: 30);
 Control.Cell.DrawingRectForBounds(newRect); //NSTextField

This doesn't change the UI.

Can you please tell me how to set text vertically center in Mac and iOS project?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
John Smith
  • 139
  • 8

1 Answers1

0

Set UiTextField Text Vertical Center in renderer as bellow:

Control.VerticalAlignment = UIControlContentVerticalAlignment.Center; //Control: UiTextField

UIControlContentVerticalAlignment

Even not set this , I found this default is vertical center in IOS, maybe somewhere your project change something.

<local:MyEntry Placeholder="placeholder" HeightRequest="100" BackgroundColor="Red"/>

enter image description here

Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
  • Thanks for iOS comment. I need solution for mac platform. in mac , Control.Alignment = NSTextAlignment.Center; property available for horizontal alignment but no any property available for vertical alignment. – John Smith May 07 '19 at 10:58
  • you can refer this link : https://stackoverflow.com/questions/11775128/set-text-vertical-center-in-nstextfield for more information. – John Smith May 07 '19 at 11:03
  • @JohnSmith Okey, thanks for link.This will be helpful for me too. :) – Junior Jiang May 08 '19 at 01:35