private UIImage CreateImage (NSString title, nfloat scale) { var titleAttrs = new UIStringAttributes () { Font = UIFont.FromName ("HelveticaNeue", 13f), ForegroundColor = Color.Gray, }; var titleBounds = new CGRect ( new CGPoint (0, 0), title.GetSizeUsingAttributes (titleAttrs) ); var image = Image.TagBackground; var imageBounds = new CGRect ( 0, 0, (float)Math.Ceiling (titleBounds.Width) + image.CapInsets.Left + image.CapInsets.Right + 4f, (float)Math.Ceiling (titleBounds.Height) + image.CapInsets.Top + image.CapInsets.Bottom ); titleBounds.X = image.CapInsets.Left + 2f; titleBounds.Y = image.CapInsets.Top; UIGraphics.BeginImageContextWithOptions (imageBounds.Size, false, scale); try { image.Draw (imageBounds); title.DrawString (titleBounds, titleAttrs); return UIGraphics.GetImageFromCurrentImageContext (); } finally { UIGraphics.EndImageContext (); } }
private CGSize GetButtonSize() { var attr = new UIStringAttributes {Font = buttonFont}; var size1 = ((NSString) ShowText).GetSizeUsingAttributes (attr); var size2 = ((NSString) HideText).GetSizeUsingAttributes (attr); return size1.Width > size2.Width ? size1 : size2; }
public static CGSize DrawString(this NSString item, CGRect rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment) { // Get paragraph style var labelStyle = NSParagraphStyle.Default.MutableCopy() as UIKit.NSMutableParagraphStyle; // Adjust alignment labelStyle.Alignment = alignment; // Adjust line break mode labelStyle.LineBreakMode = mode; // Define attributes var attributes = new UIStringAttributes() { Font = font, ForegroundColor = UIStringDrawing.FillColor, ParagraphStyle = labelStyle }; // Preform drawing item.DrawString(rect, attributes); // Return new bounding size return(new CGSize(rect.Width, rect.Height)); }
public override void Draw(CGRect frame) { //// General Declarations var context = UIGraphics.GetCurrentContext(); //// Rectangle Drawing var rectanglePath = UIBezierPath.FromRoundedRect(new CGRect(frame.GetMinX() + 14.0f, frame.GetMinY() + 2.0f, NMath.Floor((frame.Width - 14.0f) * 0.20776f + 0.5f), 21.0f), UIRectCorner.TopLeft | UIRectCorner.TopRight, new SizeF(4.0f, 4.0f)); rectanglePath.ClosePath(); Helpers.Colours.Green.SetFill(); rectanglePath.Fill(); //// Rectangle 2 Drawing var rectangle2Path = UIBezierPath.FromRect(new CGRect(frame.GetMinX(), frame.GetMinY() + 23.0f, 375.0f, 1.0f)); Helpers.Colours.Green.SetFill(); rectangle2Path.Fill(); //// Text Drawing CGRect textRect = new CGRect(frame.GetMinX() + NMath.Floor(frame.Width * 0.03733f + 0.5f), frame.GetMinY() + 3.0f, NMath.Floor(frame.Width * 0.23733f + 0.5f) - NMath.Floor(frame.Width * 0.03733f + 0.5f), 21.0f); UIColor.White.SetFill(); var textStyle = new NSMutableParagraphStyle(); textStyle.Alignment = UITextAlignment.Center; var textFontAttributes = new UIStringAttributes() { Font = UIFont.FromName("Avenir-Medium", UIFont.SmallSystemFontSize), ForegroundColor = UIColor.White, ParagraphStyle = textStyle }; var textTextHeight = new NSString(header).GetBoundingRect(new CGSize(textRect.Width, nfloat.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, textFontAttributes, null).Height; context.SaveState(); context.ClipToRect(textRect); new NSString(header).DrawString(new CGRect(textRect.GetMinX(), textRect.GetMinY() + (textRect.Height - textTextHeight) / 2.0f, textRect.Width, textTextHeight), UIFont.FromName("Avenir-Medium", UIFont.SmallSystemFontSize), UILineBreakMode.WordWrap, UITextAlignment.Center); context.RestoreState(); }
public static UIButton ConfigureTwoLineButtonWithStates(this UIButton button, string label) { var split = label.Split (); var normalText = new UIStringAttributes { Font = UIFont.SystemFontOfSize (14), ForegroundColor = CustomColors.Blue }; var selectedText = new UIStringAttributes { Font = UIFont.SystemFontOfSize (14), ForegroundColor = UIColor.White }; var normalTitle = new NSMutableAttributedString (label.ToUpper ()); normalTitle.SetAttributes (normalText.Dictionary, new NSRange (0, label.Length)); var selectedTitle = new NSMutableAttributedString (label.ToUpper ()); selectedTitle.SetAttributes (selectedText.Dictionary, new NSRange (0, label.Length)); button.SetAttributedTitle (normalTitle, UIControlState.Normal); button.SetAttributedTitle (selectedTitle, UIControlState.Selected); button.TitleLabel.Lines = 2; button.TitleLabel.TextAlignment = UITextAlignment.Center; return button; }
// // This method is invoked when the application has loaded and is ready to run. In this // method you should instantiate the window, load the UI into it and then make the window // visible. // // You have 17 seconds to return from this method, or iOS will terminate your application. // public override bool FinishedLaunching (UIApplication app, NSDictionary options) { FBSettings.DefaultAppID = AppId; FBSettings.DefaultDisplayName = DisplayName; // create a new window instance based on the screen size window = new UIWindow (UIScreen.MainScreen.Bounds); rootNavigationController = new UINavigationController (); CAGradientLayer degradado = new CAGradientLayer (); degradado.Frame = (rootNavigationController.NavigationBar.Bounds); UIGraphics.BeginImageContext (rootNavigationController.NavigationBar.Bounds.Size); degradado.Colors = new CGColor[] { UIColor.FromRGB (62, 92, 41).CGColor, UIColor.FromRGB (132, 194, 71).CGColor }; degradado.RenderInContext (UIGraphics.GetCurrentContext()); UIImage bgDegradado = UIGraphics.GetImageFromCurrentImageContext (); UIGraphics.EndImageContext (); rootNavigationController.NavigationBar.TintColor = UIColor.White; UIStringAttributes atributes = new UIStringAttributes(); atributes.ForegroundColor = UIColor.White; rootNavigationController.NavigationBar.TitleTextAttributes = atributes; rootNavigationController.NavigationBar.SetBackgroundImage (bgDegradado, UIBarMetrics.Default); // If you have defined a root view controller, set it here: // window.RootViewController = myViewController; mainView = new MainView (); rootNavigationController.PushViewController (mainView,false); // make the window visible window.RootViewController = rootNavigationController; window.MakeKeyAndVisible (); return true; }
void ChangeTheme(Page page) { var basePage = page as MainBaseContentPage; if(basePage != null) { NavigationBar.BarTintColor = basePage.BarBackgroundColor.ToUIColor(); NavigationBar.TintColor = basePage.BarTextColor.ToUIColor(); var titleAttributes = new UIStringAttributes(); titleAttributes.Font = UIFont.FromName("SegoeUI", 22); titleAttributes.ForegroundColor = basePage.BarTextColor == Color.Default ? titleAttributes.ForegroundColor ?? UINavigationBar.Appearance.TintColor : basePage.BarTextColor.ToUIColor(); NavigationBar.TitleTextAttributes = titleAttributes; UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; //Hoping to animate the color transition at some point // var atts = new UITextAttributes { // TextColor = basePage.BarTextColor.ToUIColor(), // Font = UIFont.FromName("SegoeUI", 22), // }; // UINavigationBar.Appearance.SetTitleTextAttributes(atts); // // await UIView.AnimateAsync(250, () => // { // NavigationBar.BarTintColor = basePage.BarBackgroundColor.ToUIColor(); // NavigationBar.TintColor = basePage.BarTextColor.ToUIColor(); // }); } }
public override void ViewDidLoad() { base.ViewDidLoad(); Title = "Login"; View.BackgroundColor = EnterpriseBackgroundColor; Logo.Image = Images.Logos.EnterpriseMascot; LoginButton.SetBackgroundImage(Images.Buttons.BlackButton.CreateResizableImage(new UIEdgeInsets(18, 18, 18, 18)), UIControlState.Normal); LoginButton.Enabled = true; //Set some generic shadowing LoginButton.Layer.ShadowColor = UIColor.Black.CGColor; LoginButton.Layer.ShadowOffset = new CGSize(0, 1); LoginButton.Layer.ShadowOpacity = 0.3f; var attributes = new UIStringAttributes { ForegroundColor = UIColor.LightGray, }; Domain.AttributedPlaceholder = new NSAttributedString("Domain", attributes); User.AttributedPlaceholder = new NSAttributedString("Username", attributes); Password.AttributedPlaceholder = new NSAttributedString("Password", attributes); foreach (var i in new [] { Domain, User, Password }) { i.Layer.BorderColor = UIColor.Black.CGColor; i.Layer.BorderWidth = 1; i.Layer.CornerRadius = 4; } Domain.ShouldReturn = delegate { User.BecomeFirstResponder(); return true; }; User.ShouldReturn = delegate { Password.BecomeFirstResponder(); return true; }; Password.ShouldReturn = delegate { Password.ResignFirstResponder(); LoginButton.SendActionForControlEvents(UIControlEvent.TouchUpInside); return true; }; OnActivation(d => { d(User.GetChangedObservable().Subscribe(x => ViewModel.Username = x)); d(Password.GetChangedObservable().Subscribe(x => ViewModel.Password = x)); d(Domain.GetChangedObservable().Subscribe(x => ViewModel.Domain = x)); d(LoginButton.GetClickedObservable().BindCommand(ViewModel.LoginCommand)); d(ViewModel.Bind(x => x.IsLoggingIn).SubscribeStatus("Logging in...")); d(ViewModel.LoginCommand.ThrownExceptions.Subscribe(HandleLoginException)); }); }
public void Print (object sender, EventArgs args) { UIPrintInteractionController controller = UIPrintInteractionController.SharedPrintController; if (controller == null) { Console.WriteLine ("Couldn't get shared UIPrintInteractionController"); return; } controller.CutLengthForPaper = delegate (UIPrintInteractionController printController, UIPrintPaper paper) { // Create a font with arbitrary size so that you can calculate the approximate // font points per screen point for the height of the text. UIFont font = textformatter.Font; NSString str = new NSString (textField.Text); UIStringAttributes attributes = new UIStringAttributes (); attributes.Font = font; CGSize size = str.GetSizeUsingAttributes (attributes); nfloat approximateFontPointPerScreenPoint = font.PointSize / size.Height; // Create a new font using a size that will fill the width of the paper font = SelectFont ((float)(paper.PrintableRect.Size.Width * approximateFontPointPerScreenPoint)); // Calculate the height and width of the text with the final font size attributes.Font = font; CGSize finalTextSize = str.GetSizeUsingAttributes (attributes); // Set the UISimpleTextFormatter font to the font with the size calculated textformatter.Font = font; // Calculate the margins of the roll. Roll printers may have unprintable areas // before and after the cut. We must add this to our cut length to ensure the // printable area has enough room for our text. nfloat lengthOfMargins = paper.PaperSize.Height - paper.PrintableRect.Size.Height; // The cut length is the width of the text, plus margins, plus some padding return finalTextSize.Width + lengthOfMargins + paper.PrintableRect.Size.Width * PaddingFactor; }; UIPrintInfo printInfo = UIPrintInfo.PrintInfo; printInfo.OutputType = UIPrintInfoOutputType.General; printInfo.Orientation = UIPrintInfoOrientation.Landscape; printInfo.JobName = textField.Text; textformatter = new UISimpleTextPrintFormatter (textField.Text) { Color = SelectedColor, Font = SelectFont () }; controller.PrintInfo = printInfo; controller.PrintFormatter = textformatter; if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) controller.PresentFromRectInView (printButton.Frame, View, true, PrintingComplete); else controller.Present (true, PrintingComplete); }
private static void SetText(IconButton iconButton, UIButton targetButton) { var renderedIcon = iconButton.Icon; // if no IconFontName is provided on the IconButton, default to FontAwesome var iconFontName = string.IsNullOrEmpty(iconButton.IconFontName) ? "fontawesome" : iconButton.IconFontName; var iconSize = iconButton.IconSize == default(float) ? 17f : iconButton.IconSize; var faFont = UIFont.FromName(iconFontName, iconSize); // set the icon to either be on the left or right of the button's text string combinedText = iconButton.Orientation == ImageOrientation.ImageToLeft ? string.Format("{0} {1}", renderedIcon, iconButton.Text) : string.Format("{0} {1}", iconButton.Text, renderedIcon); // string attributes for the icon var iconAttributes = new UIStringAttributes { ForegroundColor = iconButton.IconColor.ToUIColor(), BackgroundColor = targetButton.BackgroundColor, Font = faFont, TextAttachment = new NSTextAttachment() }; // string attributes for the button's text. // TODO: Calculate an appropriate BaselineOffset for the main button text in order to center it vertically relative to the icon var btnAttributes = new UIStringAttributes { BackgroundColor = iconButton.BackgroundColor.ToUIColor(), ForegroundColor = iconButton.TextColor.ToUIColor(), Font = GetButtonFont(iconButton,targetButton) }; // Give the overall string the attributes of the button's text var prettyString = new NSMutableAttributedString(combinedText,btnAttributes); // Set the font for only the icon (1 char) prettyString.SetAttributes(iconAttributes.Dictionary, iconButton.Orientation == ImageOrientation.ImageToLeft ? new NSRange(0, 1) : new NSRange(prettyString.Length - 1, 1)); // set the final formatted string as the button's text targetButton.SetAttributedTitle(prettyString, UIControlState.Normal); // center the button's contents targetButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center; targetButton.TitleLabel.TextAlignment = UITextAlignment.Center; }
public void SetTitleFont (UIColor foregroundColor) { var TitleAttr = new UIStringAttributes { ForegroundColor = foregroundColor, // Font = UIFont.FromName (fontName, fontSize), KerningAdjustment = 2 }; UINavigationBar.Appearance.TitleTextAttributes = TitleAttr; }
public override void setData() { lblTitle.Text = "Beschrijving"; //shows button depending on action add = _appController.ShowAdd; imgAction.Image = add ? UIImage.FromBundle ("SharedAssets/add_white") : UIImage.FromBundle ("SharedAssets/delete_white"); if (hidden) { lblNumber.Text = ""; lblHead.Text = "..."; lblBody.Text = _appController.CurrentTotem.body.Replace (_appController.CurrentTotem.title, "..."); } else { //styling for title (totem name) var paragraphStyleTitle = new NSMutableParagraphStyle (); paragraphStyleTitle.LineSpacing = 15; //styling for synonyms var paragraphStyleSyn = new NSMutableParagraphStyle (); paragraphStyleSyn.LineSpacing = 20; var titleAttributes = new UIStringAttributes { Font = UIFont.FromName ("VerveineW01-Regular", 35f), ParagraphStyle = paragraphStyleTitle }; var synonymsAttributes = new UIStringAttributes { Font = UIFont.FromName ("DIN-LightItalic", 17f), ParagraphStyle = paragraphStyleSyn }; var content = _appController.CurrentTotem.title; if (_appController.CurrentTotem.synonyms != null) content += " - " + _appController.CurrentTotem.synonyms; //whitespace for UI purposes content += "\n"; //applying attributes var title_synonyms = new NSMutableAttributedString (content); title_synonyms.SetAttributes (titleAttributes.Dictionary, new NSRange (0, _appController.CurrentTotem.title.Length)); title_synonyms.SetAttributes (synonymsAttributes.Dictionary, new NSRange (_appController.CurrentTotem.title.Length, (title_synonyms.Length - _appController.CurrentTotem.title.Length))); lblNumber.Text = _appController.CurrentTotem.number + ". "; lblHead.AttributedText = title_synonyms; lblBody.Text = _appController.CurrentTotem.body; } imgLine.Image = UIImage.FromBundle ("SharedAssets/Lijn_bold"); imgReturn.Image = UIImage.FromBundle ("SharedAssets/arrow_back_white"); imgHidden.Image = hidden ? UIImage.FromBundle ("SharedAssets/visibility_white") : UIImage.FromBundle ("SharedAssets/visibility_off_white"); }
public static NSAttributedString ToAttributedString(this FormattedPrice price) { var minorAttributes = new UIStringAttributes { ForegroundColor = UIColor.FromRGB(.7f, .7f, .7f), Font = UIFont.SystemFontOfSize(16), BaselineOffset = 1.5f }; var majorAttributes = new UIStringAttributes { Font = UIFont.SystemFontOfSize(23) }; var str = new NSMutableAttributedString(price.BigFigures, minorAttributes); str.Append(new NSAttributedString(price.Pips, majorAttributes)); str.Append(new NSAttributedString(price.TenthOfPip, minorAttributes)); return str; }
private void SetAttributedString() { var view = Element as CustomLabel; UIStringAttributes attr = new UIStringAttributes () { Font = Control.Font, ForegroundColor = Control.TextColor, BackgroundColor = Control.BackgroundColor, UnderlineStyle = view != null && view.IsUnderlined ? Foundation.NSUnderlineStyle.Single : Foundation.NSUnderlineStyle.None }; Control.AttributedText = new Foundation.NSAttributedString(Control.Text, attr); }
public static CGRect GetBoundingRect (this NSString This, CGSize size, NSStringDrawingOptions options, UIStringAttributes attributes, NSStringDrawingContext context) { // Define attributes var attr = new NSMutableDictionary (); attr.Add (NSFont.NameAttribute, attributes.Font.NSFont); var rect = This.BoundingRectWithSize (size, options, attr); // HACK: Cheating on the height return new CGRect(rect.Left, rect.Top , rect.Width, rect.Height * 1.5f); }
public override NSAttributedString GetMessageBubbleTopLabelAttributedText (MessagesCollectionView collectionView, NSIndexPath indexPath) { var timestampAttributes = new UIStringAttributes { ForegroundColor = Theme.Current.IncomingTextColor, BackgroundColor = UIColor.White, Font = Theme.Current.MessageFont }; MessageViewModel message = viewModel.Messages [indexPath.Row]; var timestamp = new NSAttributedString (message.Timestamp.ToString("MMM d, hh:mm tt"), timestampAttributes); return timestamp; }
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Label> e) { base.OnElementChanged (e); if (Control != null) { var attributes = new UIStringAttributes { StrikethroughStyle = NSUnderlineStyle.Single, StrikethroughColor = UIColor.Red }; Control.AttributedText = new NSAttributedString (Control.Text, attributes); } }
public override void ViewDidLoad() { base.ViewDidLoad (); UIStringAttributes myTextAttrib = new UIStringAttributes (); myTextAttrib.Font = UIFont.FromName ("Orbitron", 18); myTextAttrib.ForegroundColor = UIColor.White; this.NavigationItem.BackBarButtonItem = new UIBarButtonItem ("Back", UIBarButtonItemStyle.Plain, null); this.NavigationBar.TitleTextAttributes = myTextAttrib; UITextAttributes myTextAttrib2 = new UITextAttributes (); myTextAttrib2.Font = UIFont.FromName ("Orbitron", 18); }
public override void LayoutSubviews () { base.LayoutSubviews (); CGSize size = new CGSize (); NSString labelString = (NSString) this.TextLabel.Text ; if (labelString != null) { UIStringAttributes attribs = new UIStringAttributes { Font = this.TextLabel.Font }; size = labelString.GetSizeUsingAttributes (attribs); this.DetailTextLabel.Font = UIFont.FromName ("Helvetica", 10f); this.DetailTextLabel.Frame = new CGRect (size.Width + 20, 5, 60, 30); this.DetailTextLabel.TextAlignment = UITextAlignment.Left; } }
public void CreateButton(string title, NSObject target, Selector selector, CGPoint origin) { NSString titleString = new NSString (title); UIStringAttributes attributes = new UIStringAttributes () { Font = UIFont.SystemFontOfSize (18) }; CGSize titleSize = titleString.GetSizeUsingAttributes(attributes); UIButton button = new UIButton (new CGRect (origin.X, origin.Y, titleSize.Width, 44)); button.TitleLabel.Font = UIFont.SystemFontOfSize (14); button.Layer.BorderWidth = 1.0f; button.Layer.BorderColor = UIColor.White.CGColor; button.Layer.CornerRadius = 3.0f; button.SetTitle (title, UIControlState.Normal); button.SetTitleColor (UIColor.White, UIControlState.Normal); button.AddTarget (target, selector, UIControlEvent.TouchUpInside); this.SideDrawerView.MainView.AddSubview (button); }
void ChangeTheme(Page page) { var basePage = page as MainBaseContentPage; if(basePage != null) { NavigationBar.BarTintColor = basePage.BarBackgroundColor.ToUIColor(); NavigationBar.TintColor = basePage.BarTextColor.ToUIColor(); var titleAttributes = new UIStringAttributes(); titleAttributes.Font = UIFont.FromName("SegoeUI", 22); titleAttributes.ForegroundColor = basePage.BarTextColor == Color.Default ? titleAttributes.ForegroundColor ?? UINavigationBar.Appearance.TintColor : basePage.BarTextColor.ToUIColor(); NavigationBar.TitleTextAttributes = titleAttributes; UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; } }
public override void LayoutSubviews () { base.LayoutSubviews (); CGSize size = new CGSize (); NSString labelString = (NSString) this.TextLabel.Text ; if (labelString != null) { UIStringAttributes attribs = new UIStringAttributes { Font = this.TextLabel.Font }; size = labelString.GetSizeUsingAttributes (attribs); this.DetailTextLabel.Font = UIFont.FromName ("Helvetica", 10f); this.DetailTextLabel.Frame = new CGRect (size.Width + 66f, 10f, 49.5f, 30f); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { this.DetailTextLabel.Frame = new CGRect (size.Width + 70, 10, 49.5f, 30f); } } }
public override NSAttributedString GetCellBottomLabelAttributedText (MessagesCollectionView collectionView, NSIndexPath indexPath) { MessageViewModel message = viewModel.Messages [indexPath.Row]; if (!message.IsIncoming) { var messageStatusAttributes = new UIStringAttributes { ForegroundColor = Theme.Current.IncomingTextColor, BackgroundColor = UIColor.White, Font = Theme.Current.MessageFont }; var messageStatus = new NSAttributedString (GetMessageStatus(message), messageStatusAttributes); return messageStatus; } return null; }
private void SetPlaceholderText() { if (Element == null) { return; } string placeholderText = (string)Element.GetValue(Entry.PlaceholderProperty); var placeholderAttributes = new UIStringAttributes { ForegroundColor = UIColor.FromRGB(160/255.0f, 160/255.0f, 160/255.0f), Font = UIFont.SystemFontOfSize(24) }; NSAttributedString placeholder = new NSAttributedString(placeholderText, placeholderAttributes); Control.AttributedPlaceholder = placeholder; }
public override UITableViewCell GetCell(UITableView tableView, Foundation.NSIndexPath indexPath) { try { var cellIdentifier = new NSString("suggestion"); var cell = tableView.DequeueReusableCell(cellIdentifier) as NoRecentSearchesViewCell ?? new NoRecentSearchesViewCell(cellIdentifier); var text = results[indexPath.Row]; var hitStart = text.IndexOf("["); var hitEnd = text.LastIndexOf("]"); var hitColor = "646265".ToUIColor(); var textColor = "989898".ToUIColor(); var defaultAttributes = new UIStringAttributes { ForegroundColor = textColor, Font = UIFont.FromName("Avenir", 18) }; var hitAttributes = new UIStringAttributes { ForegroundColor = hitColor, Font = UIFont.FromName("Avenir-Medium", 18) }; text = text.Remove(hitEnd, 1); text = text.Remove(hitStart, 1); var attributedString = new NSMutableAttributedString (text); attributedString.SetAttributes(defaultAttributes.Dictionary, new NSRange(0, text.Length)); attributedString.SetAttributes(hitAttributes.Dictionary, new NSRange(0, hitEnd -1)); cell.TextLabel.AttributedText = attributedString; //cell.TextLabel.Text = text; //cell.TextLabel.Font = UIFont.FromName("Avenir-Book", 14); return cell; } catch(Exception ex) { Xamarin.Insights.Report(ex); var cell = new UITableViewCell(); cell.TextLabel.Text = results[indexPath.Row]; cell.TextLabel.Font = UIFont.FromName("Avenir-Book", 14); return cell; } }
public void CreateButton(string title, NSObject target, Selector selector) { NSString titleString = new NSString (title); UIStringAttributes attributes = new UIStringAttributes () { Font = UIFont.SystemFontOfSize (18) }; CGSize titleSize = titleString.GetSizeUsingAttributes(attributes); UIButton button = new UIButton (new CGRect (15, 15 + buttonY, titleSize.Width, 44)); button.TitleLabel.Font = UIFont.SystemFontOfSize (14); button.Layer.BorderWidth = 1.0f; button.Layer.BorderColor = UIColor.White.CGColor; button.Layer.CornerRadius = 3.0f; button.SetTitle (title, UIControlState.Normal); button.SetTitleColor (UIColor.White, UIControlState.Normal); button.AddTarget (target, selector, UIControlEvent.TouchUpInside); scrollView.AddSubview (button); buttonY += 50; scrollView.ContentSize = new CGSize (Math.Max (button.Frame.Width, scrollView.ContentSize.Width), buttonY + 15 + this.View.Bounds.Y); }
private void ConfigureAttributedTextSystemButton() { UIStringAttributes attribs = new UIStringAttributes { ForegroundColor = ApplicationColors.Blue, StrikethroughStyle = NSUnderlineStyle.Single, }; var titleAttributes = new NSAttributedString ("Button".Localize(), attribs); AttributedTextButton.SetAttributedTitle (titleAttributes, UIControlState.Normal); var highlightedTitleAttributes = new UIStringAttributes { ForegroundColor = UIColor.Green, StrikethroughStyle = NSUnderlineStyle.Thick }; var highlightedAttributedTitle = new NSAttributedString ("Button".Localize (), highlightedTitleAttributes); AttributedTextButton.SetAttributedTitle (highlightedAttributedTitle, UIControlState.Highlighted); AttributedTextButton.TouchUpInside += OnButtonClicked; }
public double MeasureTextSize(string text, double width, double fontSize, string fontName = null) { var nsText = new NSString(text); var boundSize = new SizeF((float)width, float.MaxValue); var options = NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin; if (fontName == null) { fontName = "HelveticaNeue"; } var attributes = new UIStringAttributes { Font = UIFont.FromName(fontName, (float)fontSize) }; var sizeF = nsText.GetBoundingRect(boundSize, options, attributes, null).Size; return (double)sizeF.Height + 5; }
private void SetButtonStatus(string status) { var statusAttributes = new UIStringAttributes { ForegroundColor = UIColor.FromRGBA(red: 0f, blue: 1.0f, green: 0.478431f, alpha: 1.0f), Font = UIFont.FromName("FontAwesome", 16f) }; var textAttributes = new UIStringAttributes { ForegroundColor = UIColor.FromRGBA(red: 0f, blue: 1.0f, green: 0.478431f, alpha: 1.0f), Font = UIFont.FromName("OpenSans-Light", 16f) }; var prettyString = new NSMutableAttributedString(status); prettyString.SetAttributes(statusAttributes.Dictionary, new NSRange(0, 1)); prettyString.SetAttributes(textAttributes.Dictionary, new NSRange(2, 17)); this.addToMySchedule.SetAttributedTitle(prettyString, UIControlState.Normal); }
public LabelDetailController() { coloredLabel.SetTextColor(UIColor.Purple); var attr = new UIStringAttributes { Font = UIFont.SystemFontOfSize(18f, UIFontWeight.UltraLight) }; var attrString = new NSAttributedString("Ultralight Label", attr.Dictionary); ultralightLabel.SetText(attrString); var components = new NSDateComponents { Day = 7, Month = 9, Year = 2016 }; timer.SetDate (NSCalendar.CurrentCalendar.DateFromComponents (components)); timer.Start (); }
public CustomAttributedString(IIcon icon, UIFont font, Single iconSizePx, Single iconSizeRatio, UIColor iconColor, Boolean rotate, Boolean baselineAligned) { _rotate = rotate; _baselineAligned = baselineAligned; _icon = icon.Character.ToString(); _font = font; _iconSizePx = iconSizePx; _iconSizeRatio = iconSizeRatio; _iconColor = iconColor; _rotationStartTime = DateTime.Now.Ticks; var opt = new UIStringAttributes { Font = font }; if (baselineAligned == true) opt.BaselineOffset = 0f; if (iconColor != UIColor.DarkTextColor) opt.ForegroundColor = iconColor; }
public static CGRect GetBoundingRect(this NSString This, CGSize size, NSStringDrawingOptions options, UIStringAttributes attributes, NSStringDrawingContext context) { // Define attributes var attr = new NSMutableDictionary(); attr.Add(NSFont.NameAttribute, attributes.Font.NSFont); var rect = This.BoundingRectWithSize(size, options, attr); // HACK: Cheating on the height return(new CGRect(rect.Left, rect.Top, rect.Width, rect.Height * 1.5f)); }