Created
November 30, 2017 22:55
-
-
Save rdelrosario/d2b064b5de4c7cc5e78223926ac27388 to your computer and use it in GitHub Desktop.
iOS - Font
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SetupTextFont(UILabel label,Font font,Color? titleColor) | |
{ | |
var cPage = Element as CustomPage; | |
if (cPage!=null && cPage.FormattedTitle != null && cPage.FormattedTitle.Spans.Count > 0) | |
{ | |
SetupFormattedText(titleLabel, cPage.FormattedTitle, cPage.Title); | |
} | |
else | |
{ | |
SetupText(label, (Element as Page).Title,titleColor, CustomNavigationPage.GetTitleFont(Element)); | |
} | |
if (cPage != null && cPage.FormattedSubtitle != null && cPage.FormattedSubtitle.Spans.Count > 0) | |
{ | |
subtitleLabel.Hidden = false; | |
SetupFormattedText(subtitleLabel, cPage.FormattedSubtitle, cPage.Subtitle); | |
} | |
else if (cPage != null && !string.IsNullOrEmpty(cPage.Subtitle)) | |
{ | |
subtitleLabel.Hidden = false; | |
SetupText(subtitleLabel, cPage.Subtitle, CustomNavigationPage.GetSubtitleColor(cPage), CustomNavigationPage.GetSubtitleFont(Element)); | |
subtitleLabel.SetNeedsDisplay(); | |
} | |
else | |
{ | |
subtitleLabel.Text = string.Empty; | |
subtitleLabel.Frame = CGRect.Empty; | |
subtitleLabel.Hidden = true; | |
} | |
label.SizeToFit(); | |
subtitleLabel.SizeToFit(); | |
titleView.SizeToFit(); | |
} | |
void SetupTextColor(UILabel label,UIColor color) | |
{ | |
label.TextColor = color; | |
} | |
void SetupFormattedText(UILabel label, FormattedString formattedString, string defaulTitle) | |
{ | |
label.AttributedText = formattedString.ToAttributed(Font.Default, Xamarin.Forms.Color.Default); | |
label.SetNeedsDisplay(); | |
} | |
void SetupText(UILabel label, string text,Color? textColor, Font font) | |
{ | |
if (!string.IsNullOrEmpty(text)) | |
{ | |
label.Text = text; | |
} | |
else | |
{ | |
label.Text = string.Empty; | |
label.AttributedText = new NSAttributedString(); | |
} | |
if(textColor !=null) | |
{ | |
label.TextColor = textColor?.ToUIColor(); | |
} | |
label.Font = font.ToUIFont(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment