jbowmanp1107 / ImageCropper.Maui

MIT License
43 stars 10 forks source link

Fix page title ios #14

Closed juliusdeblaaij closed 1 month ago

juliusdeblaaij commented 7 months ago

I noticed that even though the title label's text was set on iOS, at least in the code, no title was displayed. Debugging a local build showed that the text setting code was never reached because the Titlelabel was null. The TitleLabel is get only, so I coculdn't create my own Title Label. However, setting TOCropViewController.Title is written in such a way, that it creates a label only when necesarry. A quote from TOCropVIewController: "If there is no title text, inset the top of the content as high as possible"

TOCropViewController tries to take up as much space on the screen as possible, so when no Title text is set, no label is created in order to maximize space. My code change replaces

if (!string.IsNullOrWhiteSpace(imageCropper.PageTitle) && cropViewController.TitleLabel != null)
 {
      UILabel titleLabel = cropViewController.TitleLabel;
      titleLabel.Text = imageCropper.PageTitle;
 }

With:

if(imageCropper.PageTitle != null && imageCropper.PageTitle.Length > 0)
{
    cropViewController.Title = imageCropper.PageTitle;
}

as this is all that is needed to make the title display on screen.