void UpdateFitFont() { var formsView = Element as View; if (formsView.Width < 0 || formsView.Height < 0) { return; } var height = MeasureTextSize(_view.Text, formsView.Width, _orgFontSize, _view.Font.Name); var fontSize = _orgFontSize; if (SizeToFit.GetCanExpand(Element) && height < formsView.Height) { while (height < formsView.Height) { fontSize += 0.5f; height = MeasureTextSize(_view.Text, formsView.Width, fontSize, _view.Font.Name); } } while (height > formsView.Height && fontSize > 0) { fontSize -= 0.5f; height = MeasureTextSize(_view.Text, formsView.Width, fontSize, _view.Font.Name); } _view.Font = UIFont.FromName(_view.Font.Name, fontSize); var render = Platform.GetRenderer(formsView) as LabelRenderer; render.LayoutSubviews(); }
void UpdateFitFont() { var formsView = Element as Xamarin.Forms.View; if (formsView.Width < 0 || formsView.Height < 0) { return; } var nativeHeight = _view.Context.ToPixels(formsView.Height); var nativeWidth = _view.Context.ToPixels(formsView.Width); var height = MeasureTextSize(_view.Text, nativeWidth, _orgFontSize, _view.Typeface); var fontSize = _orgFontSize; if (SizeToFit.GetCanExpand(Element) && height < nativeHeight) { while (height < nativeHeight) { fontSize += 1f; height = MeasureTextSize(_view.Text, nativeWidth, fontSize, _view.Typeface); } } while (height > nativeHeight && fontSize > 0) { fontSize -= 1f; height = MeasureTextSize(_view.Text, nativeWidth, fontSize, _view.Typeface); } _view.SetTextSize(ComplexUnitType.Px, fontSize); if (!IsFastRenderer) { _view.SetHeight(Container.Height); } }