public static void SetIcon(this UIBarButtonItem btn, FontIconTemplate template, UIColor color, UIControlState state = UIControlState.Normal) { var attrs = btn.GetTitleTextAttributes(state); var size = attrs.Font != null ? attrs.Font.PointSize : 12; btn.SetIcon(template.FontIcon((float)size), color, state); }
public static void SetBarButtonItemAppearance(UIBarButtonItem.UIBarButtonItemAppearance appearance, UIColor color, UIColor highlightedColor, UIColor textColor, float cornerRadius, float borderWidth) { UIImage backButtonPortraitImage = FlatUI.BackButtonImage(color, UIBarMetrics.Default, cornerRadius, color.Darken(2), borderWidth); UIImage highlightedBackButtonPortraitImage = FlatUI.BackButtonImage(highlightedColor, UIBarMetrics.Default, cornerRadius, highlightedColor.Darken(2), borderWidth); UIImage backButtonLandscapeImage = FlatUI.BackButtonImage(color, UIBarMetrics.LandscapePhone, cornerRadius, color.Darken(2), borderWidth); UIImage highlightedBackButtonLandscapeImage = FlatUI.BackButtonImage(highlightedColor, UIBarMetrics.LandscapePhone, cornerRadius, highlightedColor.Darken(2), borderWidth); appearance.SetBackButtonBackgroundImage(backButtonPortraitImage, UIControlState.Normal, UIBarMetrics.Default); appearance.SetBackButtonBackgroundImage(backButtonLandscapeImage, UIControlState.Normal, UIBarMetrics.LandscapePhone); appearance.SetBackButtonBackgroundImage(highlightedBackButtonPortraitImage, UIControlState.Highlighted, UIBarMetrics.Default); appearance.SetBackButtonBackgroundImage(highlightedBackButtonLandscapeImage, UIControlState.Highlighted, UIBarMetrics.LandscapePhone); appearance.SetBackButtonTitlePositionAdjustment(new UIOffset(1f, 1f), UIBarMetrics.Default); appearance.SetBackButtonTitlePositionAdjustment(new UIOffset(1f, 1f), UIBarMetrics.LandscapePhone); UIImage buttonImageNormal = FlatUI.Image(color, cornerRadius, color.Darken(2), borderWidth); UIImage buttonImageHighlighted = FlatUI.Image(highlightedColor, cornerRadius, highlightedColor.Darken(2), borderWidth); appearance.SetBackgroundImage(buttonImageNormal, UIControlState.Normal, UIBarMetrics.Default); appearance.SetBackgroundImage(buttonImageHighlighted, UIControlState.Highlighted, UIBarMetrics.Default); UITextAttributes titleTextAttributes = appearance.GetTitleTextAttributes(UIControlState.Normal); if (titleTextAttributes == null) titleTextAttributes = new UITextAttributes(); titleTextAttributes.TextShadowColor = UIColor.Clear; titleTextAttributes.TextShadowOffset = new UIOffset(0, 0); titleTextAttributes.TextColor = textColor; titleTextAttributes.Font = FlatUI.FontOfSize(0); appearance.SetTitleTextAttributes(titleTextAttributes, UIControlState.Normal); appearance.SetTitleTextAttributes(titleTextAttributes, UIControlState.Highlighted); }