0

We are using DeviceDisplay.MainDisplayInfo to assign the label text in AbsoluteLayout but it works in android but not working ios as expected text value not set to exact position

App.xaml.cs

var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
float Devicedensity = mainDisplayInfo.Density;

To call these method to calculate

 public static int PixelsToDp(float pixelValue)
        {
            var dp = (int)((pixelValue) / Devicedensity);
            return dp;
        }

To calculate to add label in absolutelayout

int dpX = PixelsToDp(Value.Xaxis);
            int dpY = PixelsToDp(Value.Yaxis);

          AbsoluteLayout.SetLayoutBounds(label, new Rectangle(dpX, dpY, -1, -1));
          AbsoluteLayout.SetLayoutFlags(label, AbsoluteLayoutFlags.None);

        

myabs.Children.Add(label);

ios renderer while tap

public void TapHandler(UITapGestureRecognizer tgr)
    {
        CGPoint touchPoint = tgr.LocationInView(nativeElement);
        formsElement.OnTapEvent(Value.Xaxis = (float)touchPoint.X, Value.Yaxis = (float)touchPoint.Y);
    }
newxamarin
  • 89
  • 7

0 Answers0