Skip to content

Commit

Permalink
Use better measurements for the title
Browse files Browse the repository at this point in the history
  • Loading branch information
tj-devel709 committed Jun 20, 2024
1 parent 393046c commit 512c841
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ internal static CGRect GetTitleBoundingRect(this UIButton platformButton, double
var availableSize = new CGSize(widthConstraint, availableHeight);

var boundingRect = title.GetBoundingRect(
availableSize,
NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading,
null);

// The width is more accurate when using the device metrics but does not always return a usable height
var boundingRectWithDeviceMetrics = title.GetBoundingRect(
availableSize,
NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesDeviceMetrics,
null);

return new CGRect(boundingRect.Location, new CGSize(boundingRect.Width, Math.Min(availableHeight, boundingRect.Height)));
return new CGRect(boundingRectWithDeviceMetrics.Location, new CGSize(boundingRectWithDeviceMetrics.Width, Math.Min(availableHeight, boundingRect.Height)));
}

return CGRect.Empty;
Expand Down

0 comments on commit 512c841

Please sign in to comment.