public override void AwakeFromNib () { ivGravatar.WantsLayer = true; ivGravatar.Layer.CornerRadius = ivGravatar.Frame.Width / 2; ivGravatar.Layer.MasksToBounds = true; DisplayGravatar (XamarinAccountEmail); // Change button text color to white and centered (lame that you can't do this in IB) var coloredTitle = new NSMutableAttributedString (btnLogin.Title); var titleRange = new NSRange (0, coloredTitle.Length); coloredTitle.AddAttribute (NSAttributedString.ForegroundColorAttributeName, NSColor.White, titleRange); var centeredAttribute = new NSMutableParagraphStyle (); centeredAttribute.Alignment = NSTextAlignment.Center; coloredTitle.AddAttribute (NSAttributedString.ParagraphStyleAttributeName, centeredAttribute, titleRange); btnLogin.AttributedTitle = coloredTitle; btnLogin.Activated += (object sender, EventArgs e) => Login(); var txtDelegate = new CustomNSTextFieldDelegate (); txtDelegate.ReturnKeyPressed += () => Login(); txtPassword.Delegate = txtDelegate; txtEmail.StringValue = XamarinAccountEmail; txtEmail.FocusRingType = NSFocusRingType.None; txtPassword.FocusRingType = NSFocusRingType.None; txtPassword.SelectText (this); txtPassword.BecomeFirstResponder (); }
public HyperLink(string pretext, string text, string postext, string address, string style) : base() { this.url = new NSUrl (address); AllowsEditingTextAttributes = true; Bordered = false; DrawsBackground = false; Editable = false; Selectable = false; base.Font = NSFontManager.SharedFontManager.FontWithFamily ( "Lucida Grande", NSFontTraitMask.Condensed, 0, 13); NSData name_data = NSData.FromString (pretext+"<a href='" + this.url + "' "+style+" >" + text + "</a>"+postext); NSDictionary name_dictionary = new NSDictionary(); NSAttributedString name_attributes = new NSAttributedString (name_data, new NSUrl ("file://"), out name_dictionary); NSMutableAttributedString s = new NSMutableAttributedString (); s.Append (name_attributes); Cell.AttributedStringValue = s; SizeToFit (); }
public SparkleDataSource(List<SparklePlugin> plugins) { Items = new List <object> (); Cells = new NSAttributedString [plugins.Count]; int i = 0; foreach (SparklePlugin plugin in plugins) { Items.Add (plugin); NSTextFieldCell cell = new NSTextFieldCell (); NSData data = NSData.FromString ( "<font face='Lucida Grande'><b>" + plugin.Name + "</b></font>"); NSDictionary dictionary = new NSDictionary(); NSAttributedString attributes = new NSAttributedString ( data, new NSUrl ("file://"), out dictionary); NSMutableAttributedString mutable_attributes = new NSMutableAttributedString (attributes); mutable_attributes.Append (new NSAttributedString ("\n" + plugin.Description)); cell.SetAttributedStringValue (mutable_attributes); Cells [i] = (NSAttributedString) cell.ObjectValue; i++; } }
public override void AwakeFromNib () { base.AwakeFromNib (); this.AddressLabel.StringValue = Properties_Resources.EnterWebAddress; this.UserLabel.StringValue = Properties_Resources.User + ": "; this.PasswordLabel.StringValue = Properties_Resources.Password + ": "; this.AddressDelegate = new TextFieldDelegate(); this.AddressText.Delegate = this.AddressDelegate; this.UserDelegate = new TextFieldDelegate(); this.UserText.Delegate = this.UserDelegate; this.PasswordDelegate = new TextFieldDelegate(); this.PasswordText.Delegate = this.PasswordDelegate; this.ContinueButton.Title = Properties_Resources.Continue; this.CancelButton.Title = Properties_Resources.Cancel; this.AddressText.StringValue = (Controller.PreviousAddress == null || String.IsNullOrEmpty (Controller.PreviousAddress.ToString ())) ? "https://" : Controller.PreviousAddress.ToString (); this.UserText.StringValue = String.IsNullOrEmpty (Controller.saved_user) ? Environment.UserName : Controller.saved_user; // this.PasswordText.StringValue = String.IsNullOrEmpty (Controller.saved_password) ? "" : Controller.saved_password; this.PasswordText.StringValue = ""; // Cmis server address help link string helpLabel = Properties_Resources.Help + ": "; string helpLink = Properties_Resources.WhereToFind; string addressUrl = @"https://github.com/aegif/CmisSync/wiki/What-address"; this.AddressHelp.AllowsEditingTextAttributes = true; this.AddressHelp.Selectable = true; var attrStr = new NSMutableAttributedString(helpLabel + helpLink); var labelRange = new NSRange(0, helpLabel.Length); var linkRange = new NSRange(helpLabel.Length, helpLink.Length); var url = new NSUrl(addressUrl); var font = this.AddressHelp.Font; var paragraph = new NSMutableParagraphStyle() { LineBreakMode = this.AddressHelp.Cell.LineBreakMode, Alignment = this.AddressHelp.Alignment }; attrStr.BeginEditing(); attrStr.AddAttribute(NSAttributedString.LinkAttributeName, url, linkRange); attrStr.AddAttribute(NSAttributedString.ForegroundColorAttributeName, NSColor.Blue, linkRange); attrStr.AddAttribute(NSAttributedString.ForegroundColorAttributeName, NSColor.Gray, labelRange); attrStr.AddAttribute(NSAttributedString.UnderlineStyleAttributeName, new NSNumber(1), linkRange); attrStr.AddAttribute(NSAttributedString.FontAttributeName, font, new NSRange(0, attrStr.Length)); attrStr.AddAttribute(NSAttributedString.ParagraphStyleAttributeName, paragraph, new NSRange(0, attrStr.Length)); attrStr.EndEditing(); this.AddressHelp.AttributedStringValue = attrStr; InsertEvent (); // Must be called after InsertEvent() CheckTextFields (); }
public override void AwakeFromNib () { ivStatusImage.WantsLayer = true; View.Gear = ivStatusImage; btnTryAgain.Hidden = true; btnTryAgain.Activated += (object sender, EventArgs e) => ProcessOrder(); // Change button text color to white and centered (lame that you can't do this in IB) var coloredTitle = new NSMutableAttributedString (btnTryAgain.Title); var titleRange = new NSRange (0, coloredTitle.Length); coloredTitle.AddAttribute (NSAttributedString.ForegroundColorAttributeName, NSColor.White, titleRange); var centeredAttribute = new NSMutableParagraphStyle (); centeredAttribute.Alignment = NSTextAlignment.Center; coloredTitle.AddAttribute (NSAttributedString.ParagraphStyleAttributeName, centeredAttribute, titleRange); btnTryAgain.AttributedTitle = coloredTitle; ProcessOrder (); }
public override void AwakeFromNib () { viewEmptyBasket.WantsLayer = true; viewEmptyBasket.Layer = new CALayer () {BackgroundColor = NSColor.White.CGColor}; viewBasket.WantsLayer = true; viewBasket.Layer = new CALayer () {BackgroundColor = NSColor.White.CGColor}; // Change button text color to white and centered (lame that you can't do this in IB) var coloredTitle = new NSMutableAttributedString (btnCheckout.Title); var titleRange = new NSRange (0, coloredTitle.Length); coloredTitle.AddAttribute (NSAttributedString.ForegroundColorAttributeName, NSColor.White, titleRange); var centeredAttribute = new NSMutableParagraphStyle (); centeredAttribute.Alignment = NSTextAlignment.Center; coloredTitle.AddAttribute (NSAttributedString.ParagraphStyleAttributeName, centeredAttribute, titleRange); btnCheckout.AttributedTitle = coloredTitle; tvBasketProducts.Source = new ShoppingBasketTableViewSource (); btnCheckout.Activated += (object sender, EventArgs e) => CheckoutInitiated(); View.ViewController = this; RefreshBasket (); }
public override void AwakeFromNib () { // Change button text color to white and centered (lame that you can't do this in IB) var coloredTitle = new NSMutableAttributedString (btnPlaceOrder.Title); var titleRange = new NSRange (0, coloredTitle.Length); coloredTitle.AddAttribute (NSAttributedString.ForegroundColorAttributeName, NSColor.White, titleRange); var centeredAttribute = new NSMutableParagraphStyle (); centeredAttribute.Alignment = NSTextAlignment.Center; coloredTitle.AddAttribute (NSAttributedString.ParagraphStyleAttributeName, centeredAttribute, titleRange); btnPlaceOrder.AttributedTitle = coloredTitle; txtFirstName.StringValue = _user.FirstName; txtLastName.StringValue = _user.LastName; LoadCountries (); cbCountry.Changed += (object sender, EventArgs e) => { LoadStates(); }; txtAddress1.SelectText (this); txtAddress1.BecomeFirstResponder (); btnPlaceOrder.Activated += OnBtnPlaceOrder; }
public SparkleDataSource(List<SparklePlugin> plugins) { Items = new List <object> (); Cells = new NSAttributedString [plugins.Count]; SelectedCells = new NSAttributedString [plugins.Count]; int i = 0; foreach (SparklePlugin plugin in plugins) { Items.Add (plugin); NSTextFieldCell cell = new NSTextFieldCell (); NSData name_data = NSData.FromString ("<font face='Lucida Grande'><b>" + plugin.Name + "</b></font>"); NSDictionary name_dictionary = new NSDictionary(); NSAttributedString name_attributes = new NSAttributedString ( name_data, new NSUrl ("file://"), out name_dictionary); NSData description_data = NSData.FromString ( "<small><font style='line-height: 150%' color='#aaa' face='Lucida Grande'>" + plugin.Description + "</font></small>"); NSDictionary description_dictionary = new NSDictionary(); NSAttributedString description_attributes = new NSAttributedString ( description_data, new NSUrl ("file://"), out description_dictionary); NSMutableAttributedString mutable_attributes = new NSMutableAttributedString (name_attributes); mutable_attributes.Append (new NSAttributedString ("\n")); mutable_attributes.Append (description_attributes); cell.AttributedStringValue = mutable_attributes; Cells [i] = (NSAttributedString) cell.ObjectValue; NSTextFieldCell selected_cell = new NSTextFieldCell (); NSData selected_name_data = NSData.FromString ( "<font color='white' face='Lucida Grande'><b>" + plugin.Name + "</b></font>"); NSDictionary selected_name_dictionary = new NSDictionary (); NSAttributedString selected_name_attributes = new NSAttributedString ( selected_name_data, new NSUrl ("file://"), out selected_name_dictionary); NSData selected_description_data = NSData.FromString ( "<small><font style='line-height: 150%' color='#9bbaeb' face='Lucida Grande'>" + plugin.Description + "</font></small>"); NSDictionary selected_description_dictionary = new NSDictionary (); NSAttributedString selected_description_attributes = new NSAttributedString ( selected_description_data, new NSUrl ("file://"), out selected_description_dictionary); NSMutableAttributedString selected_mutable_attributes = new NSMutableAttributedString (selected_name_attributes); selected_mutable_attributes.Append (new NSAttributedString ("\n")); selected_mutable_attributes.Append (selected_description_attributes); selected_cell.AttributedStringValue = selected_mutable_attributes; SelectedCells [i] = (NSAttributedString) selected_cell.ObjectValue; i++; } }
private static NSMutableAttributedString buildAttributedString(string text, CTFont font, Color? fontColor=null) { // Create a new attributed string from text NSMutableAttributedString atts = new NSMutableAttributedString(text); var attRange = new NSRange(0, atts.Length); var attsDic = new NSMutableDictionary(); // Font attribute NSObject fontObject = new NSObject(font.Handle); attsDic.Add(FontAttributedName, fontObject); // -- end font if (fontColor.HasValue) { // Font color var fc = fontColor.Value; NSColor color = NSColor.FromDeviceRgba(fc.R / 255f, fc.G / 255f, fc.B / 255f, fc.A / 255f); NSObject colorObject = new NSObject(color.Handle); attsDic.Add(ForegroundColorAttributedName, colorObject); // -- end font Color } if (underLine) { // Underline int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single; int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid; var attss = single | solid; var underlineObject = NSNumber.FromInt32(attss); //var under = NSAttributedString.UnderlineStyleAttributeName.ToString(); attsDic.Add(UnderlineStyleAttributeName, underlineObject); // --- end underline } if (strikeThrough) { // StrikeThrough // NSColor bcolor = NSColor.Blue; // NSObject bcolorObject = new NSObject(bcolor.Handle); // attsDic.Add(NSAttributedString.StrikethroughColorAttributeName, bcolorObject); int stsingle = (int)MonoMac.AppKit.NSUnderlineStyle.Single; int stsolid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid; var stattss = stsingle | stsolid; var stunderlineObject = NSNumber.FromInt32(stattss); attsDic.Add(StrikethroughStyleAttributeName, stunderlineObject); // --- end underline } // Text alignment var alignment = CTTextAlignment.Left; var alignmentSettings = new CTParagraphStyleSettings(); alignmentSettings.Alignment = alignment; var paragraphStyle = new CTParagraphStyle(alignmentSettings); NSObject psObject = new NSObject(paragraphStyle.Handle); // end text alignment attsDic.Add(ParagraphStyleAttributeName, psObject); atts.SetAttributes(attsDic, attRange); return atts; }
public override void DrawInteriorWithFrame(CGRect cellFrame, NSView inView) { var frame = cellFrame; var data = ObjectValue as MacImageData; if (data != null) { if (data.Image != null) { var imageSize = data.Image.Size; if (imageSize.Width > 0 && imageSize.Height > 0) { var newHeight = (nfloat)Math.Min(imageSize.Height, frame.Height); var newWidth = (nfloat)(imageSize.Width * newHeight / imageSize.Height); if (DrawsBackground && !Highlighted) { var g = NSGraphicsContext.CurrentContext.GraphicsPort; g.SetFillColor(BackgroundColor.CGColor); g.FillRect(new CGRect(frame.X, frame.Y, newWidth + ImagePadding, frame.Height)); } var imageRect = new CGRect(frame.X, frame.Y, newWidth, newHeight); imageRect.Y += (frame.Height - newHeight) / 2; nfloat alpha = Enabled ? 1 : (nfloat)0.5; if (data.Image.RespondsToSelector(new Selector(selDrawInRectFromRectOperationFractionRespectFlippedHints))) // 10.6+ data.Image.Draw(imageRect, new CGRect(CGPoint.Empty, data.Image.Size), NSCompositingOperation.SourceOver, alpha, true, null); else { // 10.5- #pragma warning disable 618 data.Image.Flipped = ControlView.IsFlipped; #pragma warning restore 618 data.Image.Draw(imageRect, new CGRect(CGPoint.Empty, data.Image.Size), NSCompositingOperation.SourceOver, alpha); } frame.Width -= newWidth + ImagePadding; frame.X += newWidth + ImagePadding; } } } var titleSize = AttributedStringValue.Size; // test to see if the text height is bigger then the cell, if it is, // don't try to center it or it will be pushed up out of the cell! if (titleSize.Height < frame.Size.Height) { //frame.Y = frame.Y + (frame.Size.Height - titleSize.Height) / 2; } if (UseTextShadow) { var str = new NSMutableAttributedString(StringValue); str.AddAttribute(NSStringAttributeKey.Shadow, Highlighted ? TextHighlightShadow : TextShadow, new NSRange(0, (int)str.Length)); AttributedStringValue = str; } base.DrawInteriorWithFrame(frame, inView); }
public override void DrawInteriorWithFrame (SD.RectangleF cellFrame, NSView inView) { var data = ObjectValue as MacImageData; if (data != null) { if (data.Image != null) { var imageSize = data.Image.Size; if (imageSize.Width > 0 && imageSize.Height > 0) { var newHeight = Math.Min (imageSize.Height, cellFrame.Height); var newWidth = imageSize.Width * newHeight / imageSize.Height; var imageRect = new SD.RectangleF (cellFrame.X, cellFrame.Y, newWidth, newHeight); imageRect.Y += (cellFrame.Height - newHeight) / 2; if (data.Image.RespondsToSelector (new Selector (selDrawInRectFromRectOperationFractionRespectFlippedHints))) // 10.6+ data.Image.Draw (imageRect, new SD.RectangleF (SD.PointF.Empty, data.Image.Size), NSCompositingOperation.SourceOver, 1, true, null); else { // 10.5- #pragma warning disable 618 data.Image.Flipped = this.ControlView.IsFlipped; #pragma warning restore 618 data.Image.Draw (imageRect, new SD.RectangleF (SD.PointF.Empty, data.Image.Size), NSCompositingOperation.SourceOver, 1); } cellFrame.Width -= newWidth + ImagePadding; cellFrame.X += newWidth + ImagePadding; } } } SD.SizeF titleSize = this.AttributedStringValue.Size; // test to see if the text height is bigger then the cell, if it is, // don't try to center it or it will be pushed up out of the cell! if (titleSize.Height < cellFrame.Size.Height) { cellFrame.Y = cellFrame.Y + (cellFrame.Size.Height - titleSize.Height) / 2; } if (UseTextShadow) { var str = new NSMutableAttributedString(this.StringValue); str.AddAttribute (NSAttributedString.ShadowAttributeName, this.Highlighted ? TextHighlightShadow : TextShadow, new NSRange(0, str.Length)); this.AttributedStringValue = str; } base.DrawInteriorWithFrame (cellFrame, inView); }
static NSAttributedString GetAttributedString(string text) { var attrStr = new NSMutableAttributedString (text); var range = new NSRange (0, attrStr.Length); var singleUnderlineStyle = NSNumber.FromInt32 ((int)NSUnderlineStyle.Single); attrStr.AddAttribute (NSStringAttributeKey.ForegroundColor, Toolkit.CurrentEngine.Defaults.FallbackLinkColor.ToNSColor (), range); attrStr.AddAttribute (NSStringAttributeKey.UnderlineStyle, singleUnderlineStyle, range); return attrStr; }
public SparkleLink(string text, string address) : base() { this.url = new NSUrl (address); AllowsEditingTextAttributes = true; BackgroundColor = NSColor.White; Bordered = false; DrawsBackground = false; Editable = false; Selectable = false; NSData name_data = NSData.FromString ("<a href='" + this.url + "' style='font-size: 9pt; font-family: \"Helvetica Neue\"; color: #739ECF'>" + text + "</a></font>"); NSDictionary name_dictionary = new NSDictionary(); NSAttributedString name_attributes = new NSAttributedString (name_data, new NSUrl ("file://"), out name_dictionary); NSMutableAttributedString s = new NSMutableAttributedString (); s.Append (name_attributes); Cell.AttributedStringValue = s; SizeToFit (); }
private void UpdateStatusBar() { if (mediaListController.Count < 1) { statusFilename.StringValue = statusTimestamp.StringValue = statusGps.StringValue = statusKeywords.StringValue = ""; statusIndex.StringValue = "No files"; return; } var mm = mediaListController.Current; statusFilename.StringValue = mm.Name; var timestamp = mm.Timestamp.ToString("yyyy/MM/dd HH:mm:ss"); if (mm.FileAndExifTimestampMatch) { statusTimestamp.StringValue = timestamp; } else { var str = new NSMutableAttributedString(timestamp); str.AddAttribute( NSAttributedString.ForegroundColorAttributeName, NSColor.Yellow, new NSRange(0, timestamp.Length)); str.AddAttribute( NSAttributedString.UnderlineStyleAttributeName, new NSNumber((int) NSUnderlineStyle.Single), new NSRange(0, timestamp.Length)); statusTimestamp.AttributedStringValue = str; } statusIndex.StringValue = String.Format( "{0} of {1}", mediaListController.CurrentIndex + 1, mediaListController.Count); statusKeywords.StringValue = mm.Keywords; statusGps.StringValue = ""; if (mm.HasPlaceName) { SetStatusGps(mm); } else { ClearStatusGps(); Task.Run( () => { mm.ToPlaceName(); BeginInvokeOnMainThread( () => { SetStatusGps(mm); }); }); } }
private NSMutableAttributedString buildAttributedString(string text, Font font, StringFormat format = null, Color? fontColor=null) { // Create a new attributed string definition var ctAttributes = new CTStringAttributes (); // Font attribute ctAttributes.Font = font.nativeFont; // -- end font if (format != null && (format.FormatFlags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical) { //ctAttributes.VerticalForms = true; } if (fontColor.HasValue) { // Font color var fc = fontColor.Value; var cgColor = new CGColor(fc.R / 255f, fc.G / 255f, fc.B / 255f, fc.A / 255f); ctAttributes.ForegroundColor = cgColor; ctAttributes.ForegroundColorFromContext = false; // -- end font Color } if (font.Underline) { // Underline #if MONOMAC int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single; int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid; var attss = single | solid; ctAttributes.UnderlineStyleValue = attss; #else ctAttributes.UnderlineStyleValue = 1; #endif // --- end underline } if (font.Strikeout) { // StrikeThrough #if MONOMAC int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single; int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid; var attss = single | solid; ctAttributes.UnderlineStyleValue = attss; #else ctAttributes.UnderlineStyleValue = 1; #endif // --- end StrikeThrough } var alignment = CTTextAlignment.Left; var alignmentSettings = new CTParagraphStyleSettings(); alignmentSettings.Alignment = alignment; var paragraphStyle = new CTParagraphStyle(alignmentSettings); ctAttributes.ParagraphStyle = paragraphStyle; // end text alignment NSMutableAttributedString atts = new NSMutableAttributedString(text,ctAttributes.Dictionary); return atts; }
public SparkleDataSource (float backing_scale_factor, List<Preset> presets) { Items = new List <object> (); Cells = new NSAttributedString [presets.Count]; SelectedCells = new NSAttributedString [presets.Count]; this.backing_scale_factor = (int) backing_scale_factor; int i = 0; foreach (Preset preset in presets) { Items.Add (preset); NSTextFieldCell cell = new NSTextFieldCell (); NSData name_data = NSData.FromString ("<font face='" + UserInterface.FontName + "'><b>" + preset.Name + "</b></font>"); NSDictionary name_dictionary = new NSDictionary(); NSAttributedString name_attributes = new NSAttributedString ( name_data, new NSUrl ("file://"), out name_dictionary); NSData description_data = NSData.FromString ( "<small><font style='line-height: 150%' color='#aaa' face='" + UserInterface.FontName + "'>" + preset.Description + "</font></small>"); NSDictionary description_dictionary = new NSDictionary(); NSAttributedString description_attributes = new NSAttributedString ( description_data, new NSUrl ("file://"), out description_dictionary); NSMutableAttributedString mutable_attributes = new NSMutableAttributedString (name_attributes); mutable_attributes.Append (new NSAttributedString ("\n")); mutable_attributes.Append (description_attributes); cell.AttributedStringValue = mutable_attributes; Cells [i] = (NSAttributedString) cell.ObjectValue; NSTextFieldCell selected_cell = new NSTextFieldCell (); NSData selected_name_data = NSData.FromString ( "<font color='white' face='" + UserInterface.FontName +"'><b>" + preset.Name + "</b></font>"); NSDictionary selected_name_dictionary = new NSDictionary (); NSAttributedString selected_name_attributes = new NSAttributedString ( selected_name_data, new NSUrl ("file://"), out selected_name_dictionary); NSData selected_description_data = NSData.FromString ( "<small><font style='line-height: 150%' color='#9bbaeb' face='" + UserInterface.FontName + "'>" + preset.Description + "</font></small>"); NSDictionary selected_description_dictionary = new NSDictionary (); NSAttributedString selected_description_attributes = new NSAttributedString ( selected_description_data, new NSUrl ("file://"), out selected_description_dictionary); NSMutableAttributedString selected_mutable_attributes = new NSMutableAttributedString (selected_name_attributes); selected_mutable_attributes.Append (new NSAttributedString ("\n")); selected_mutable_attributes.Append (selected_description_attributes); selected_cell.AttributedStringValue = selected_mutable_attributes; SelectedCells [i] = (NSAttributedString) selected_cell.ObjectValue; i++; } }
static NSAttributedString GetAttributedString (string text) { var attrStr = new NSMutableAttributedString (text); var range = new NSRange (0, attrStr.Length); var singleUnderlineStyle = NSNumber.FromInt32 ((int)NSUnderlineStyle.Single); attrStr.AddAttribute (NSStringAttributeKey.ForegroundColor, NSColor.Blue, range); attrStr.AddAttribute (NSStringAttributeKey.UnderlineStyle, singleUnderlineStyle, range); return attrStr; }
public void DisplayInfo(string message) { var attr = new NSMutableAttributedString(message); attr.AddAttribute( NSAttributedString.BackgroundColorAttributeName, NSColor.FromDeviceRgba(0, 0, 0, 0.75f), new NSRange(0, message.Length)); infoText.AttributedStringValue = attr; }
private static NSMutableAttributedString buildAttributedString(string text, Font font, Color? fontColor=null) { // Create a new attributed string definition var ctAttributes = new CTStringAttributes (); // Font attribute ctAttributes.Font = font.nativeFont; // -- end font if (fontColor.HasValue) { // Font color var fc = fontColor.Value; var cgColor = new CGColor(fc.R / 255f, fc.G / 255f, fc.B / 255f, fc.A / 255f); ctAttributes.ForegroundColor = cgColor; ctAttributes.ForegroundColorFromContext = false; // -- end font Color } if (font.Underline) { // Underline #if MONOMAC int single = (int)MonoMac.AppKit.NSUnderlineStyle.Single; int solid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid; var attss = single | solid; ctAttributes.UnderlineStyleValue = attss; #else ctAttributes.UnderlineStyleValue = 1; #endif // --- end underline } if (font.Strikeout) { // StrikeThrough // NSColor bcolor = NSColor.Blue; // NSObject bcolorObject = new NSObject(bcolor.Handle); // attsDic.Add(NSAttributedString.StrikethroughColorAttributeName, bcolorObject); // #if MACOS // int stsingle = (int)MonoMac.AppKit.NSUnderlineStyle.Single; // int stsolid = (int)MonoMac.AppKit.NSUnderlinePattern.Solid; // var stattss = stsingle | stsolid; // var stunderlineObject = NSNumber.FromInt32(stattss); // #else // var stunderlineObject = NSNumber.FromInt32 (1); // #endif // // attsDic.Add(StrikethroughStyleAttributeName, stunderlineObject); // --- end underline } // Text alignment var alignment = CTTextAlignment.Left; var alignmentSettings = new CTParagraphStyleSettings(); alignmentSettings.Alignment = alignment; var paragraphStyle = new CTParagraphStyle(alignmentSettings); ctAttributes.ParagraphStyle = paragraphStyle; // end text alignment NSMutableAttributedString atts = new NSMutableAttributedString(text,ctAttributes.Dictionary); return atts; }
static NSAttributedString GetAttributedString (string text) { var attrStr = new NSMutableAttributedString (text); var range = new NSRange (0, attrStr.Length); attrStr.AddAttribute (NSAttributedString.ForegroundColorAttributeName, NSColor.Blue, range); attrStr.AddAttribute (NSAttributedString.UnderlineStyleAttributeName, NSNumber.FromInt32 ((int)MonoMac.AppKit.NSUnderlineStyle.Single), range); return attrStr; }