void UpdateUI(NextPillsMessage message) { ToggleUI(); if (message.Name != null) { var attrString = new NSAttributedString (message.Name, new UIStringAttributes { Font = UIFont.SystemFontOfSize (20, UIFontWeight.Light)}); nameLabel.SetText(attrString); } if (message.LeftTime != null) { var attrString = new NSAttributedString(message.LeftTime, new UIStringAttributes { Font = UIFont.SystemFontOfSize(14, UIFontWeight.Medium) }); leftTimeLabel.SetText(attrString); } int percentage; if (message.Percentage < 0 || message.Percentage > 99) percentage = 0; else percentage = message.Percentage; countdownGroup.SetBackgroundImage("countdownWatch"); countdownGroup.StartAnimating(new NSRange(0, percentage), 1, 1); }
private static Tuple<NSMutableAttributedString,List<NewsCellView.Link>> CreateAttributedStringFromBlocks(UIFont font, UIColor primaryColor, IEnumerable<TextBlock> blocks) { var attributedString = new NSMutableAttributedString(); var links = new List<NewsCellView.Link>(); nint lengthCounter = 0; int i = 0; foreach (var b in blocks) { UIColor color = null; if (b.Tapped != null) color = LinkColor; color = color ?? primaryColor; var ctFont = new CoreText.CTFont(font.Name, font.PointSize); var str = new NSAttributedString(b.Value, new CoreText.CTStringAttributes() { ForegroundColor = color.CGColor, Font = ctFont }); attributedString.Append(str); var strLength = str.Length; if (b.Tapped != null) { var weakTapped = new WeakReference<Action>(b.Tapped); links.Add(new NewsCellView.Link { Range = new NSRange(lengthCounter, strLength), Callback = () => weakTapped.Get()?.Invoke(), Id = i++ }); } lengthCounter += strLength; } return new Tuple<NSMutableAttributedString, List<NewsCellView.Link>>(attributedString, links); }
public DetailViewController(RSSFeedItem item) : base(UITableViewStyle.Grouped, null, true) { var attributes = new NSAttributedStringDocumentAttributes(); attributes.DocumentType = NSDocumentType.HTML; attributes.StringEncoding = NSStringEncoding.UTF8; var error = new NSError(); var htmlString = new NSAttributedString(item.Description, attributes, ref error); Root = new RootElement(item.Title) { new Section{ new StringElement(item.Author), new StringElement(item.PublishDate), new StyledMultilineElement(htmlString), new HtmlElement("Full Article", item.Link) } }; NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Action, async delegate { var message = item.Title + " " + item.Link + " #PlanetXamarin"; var social = new UIActivityViewController(new NSObject[] { new NSString(message)}, new UIActivity[] { new UIActivity() }); PresentViewController(social, true, null); }); }
public NSAttributedString GetAttributedText() { string path = null; NSError error = new NSError (); if (TextStoragePath != null) path = NSBundle.MainBundle.PathForResource ("TextFiles/" + TextStoragePath[0], ""); else path = NSBundle.MainBundle.PathForResource ("TextFiles/" + Title, "rtf"); if (path == null) return new NSAttributedString (""); if (StrRichFormatting) { // Load the file from disk var attributedString = new NSAttributedString (new NSUrl (path, false), null, ref error); // Make a copy we can alter var attributedTextHolder = new NSMutableAttributedString (attributedString); attributedTextHolder.AddAttributes (new UIStringAttributes () { Font = UIFont.PreferredBody }, new NSRange (0, attributedTextHolder.Length)); AttributedText = (NSAttributedString)attributedTextHolder.Copy (); } else { string newFlatText = new NSAttributedString (new NSUrl (path, false), null, ref error).Value; AttributedText = new NSAttributedString (newFlatText, font: UIFont.PreferredBody); } return AttributedText; }
public override NSAttributedString GetAttributedTitle (UIPickerView pickerView, System.nint row, System.nint component) { var title = items [(int) row]; var font = UIFont.FromName ("SegoeUI-Light", 17f); var attributedTitle = new NSAttributedString (title, font, UIColor.White, null, null, null, (NSLigatureType) 1, 0, (NSUnderlineStyle) 0, null, 0, NSUnderlineStyle.None); return attributedTitle; }
void SetPlaceholderTextColor (MyEntry view) { if (string.IsNullOrEmpty (view.Placeholder) == false && view.PlaceholderColor != Color.Default) { var placeholderString = new NSAttributedString (view.Placeholder, new UIStringAttributes { ForegroundColor = view.PlaceholderColor.ToUIColor () }); Control.AttributedPlaceholder = placeholderString; } }
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName.Equals("Text") && Control != null) { // http://forums.xamarin.com/discussion/15530/nsattributedstringdocumentattributes-exception-on-ios-6 NSParagraphStyle ps = NSParagraphStyle.Default; NSDictionary dict = new NSMutableDictionary() { { UIStringAttributeKey.Font, ((ExtendedLabel)Element).Font.ToUIFont() }, }; var attr = new NSAttributedStringDocumentAttributes(dict); var nsError = new NSError(); // This line announces, that content is html. attr.DocumentType = NSDocumentType.HTML; attr.StringEncoding = NSStringEncoding.UTF8; var html = ((ExtendedLabel)Element).TextExt + Environment.NewLine; NSString htmlString = new NSString(html); NSData htmlData = htmlString.Encode(NSStringEncoding.UTF8); NSAttributedString attrStr = new NSAttributedString(htmlData, attr, out dict, ref nsError); Control.AttributedText = attrStr; Control.SizeToFit(); Control.SetNeedsLayout(); Element.HeightRequest = Control.Bounds.Height; return; } if (e.PropertyName == "Height" || e.PropertyName == "Width") { // We calculate the correct height, because of the attributed string, Xamarin.Forms don't do it correct var width = (float)((ExtendedLabel)Element).Width; // Only do this, if we have a valid width if (width != -1) { var rect = Control.AttributedText.GetBoundingRect(new CoreGraphics.CGSize(width, float.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading, null); if (rect.Height != ((ExtendedLabel)Element).Height) { ((ExtendedLabel)Element).HeightRequest = rect.Height; } } } base.OnElementPropertyChanged(sender, e); }
public LiveVariableView(string image, string title, double oldPrice, double discount) { Layer.CornerRadius = 5; ClipsToBounds = true; BackgroundColor = UIColor.White; this.image = new UIImageView { Image = UIImage.FromBundle(image), ContentMode = UIViewContentMode.ScaleAspectFit, }; this.title = new UILabel { Text = title, Font = UIFont.FromName("Gotham-Medium", 12), TextColor = Styling.Colors.TextLightBlue }; this.oldPrice = new UILabel { Font = UIFont.FromName("Gotham-Light", 10), TextColor = Styling.Colors.TextLightBlue }; var attributedString = new NSAttributedString(oldPrice.ToString("##.00"), strikethroughStyle: NSUnderlineStyle.Single); this.oldPrice.AttributedText = attributedString; this.newPrice = new UILabel { Font = UIFont.FromName("Gotham-Medium", 12), TextColor = Styling.Colors.TextBlue }; double oldprice; double.TryParse(this.oldPrice.Text, out oldprice); newPrice.Text = (oldprice - oldPrice * discount).ToString("##.00"); this.AddSubviews(this.image, this.title, this.oldPrice, this.newPrice); this.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints(); this.AddConstraints( this.oldPrice.WithSameBottom(this).Minus(20), this.oldPrice.WithSameCenterX(this).Minus(20), this.newPrice.WithSameCenterY(this.oldPrice), this.newPrice.ToRightOf(this.oldPrice).Plus(10), this.title.WithSameCenterX(this), this.title.Above(this.oldPrice).Minus(15), this.image.WithSameCenterX(this), this.image.WithSameTop(this).Plus(20), this.image.WithSameLeft(this), this.image.WithSameRight(this) ); }
void ConfigureAttributedTextSystemButton () { const string buttonTitle = "Button"; var normalAttributedTitle = new NSAttributedString (buttonTitle, foregroundColor: UIColor.Blue, strikethroughStyle: NSUnderlineStyle.Single); AttributedTextButton.SetAttributedTitle (normalAttributedTitle, UIControlState.Normal); var highlightedAttributedTitle = new NSAttributedString (buttonTitle, foregroundColor: UIColor.Green, strikethroughStyle: NSUnderlineStyle.Thick); AttributedTextButton.SetAttributedTitle (highlightedAttributedTitle, UIControlState.Highlighted); }
void TextChanged () { SetNeedsDisplay (); ClearPreviousLayoutInformation (); attributedString = new NSAttributedString (Text, attributes); framesetter = new CTFramesetter (attributedString); UIBezierPath path = UIBezierPath.FromRect (Bounds); frame = framesetter.GetFrame (new NSRange (0, 0), path.CGPath, null); }
public override NSAttributedString GetAttributedTitle (UIPickerView pickerView, nint row, nint component) { var title = items [(int) row]; int hyphenIndex = title.IndexOf ("-"); // Added to attempt to solve issue with displaying -xx in picker if (hyphenIndex > 0) title = title.Substring (0, hyphenIndex); var font = UIFont.FromName ("SegoeUI-Light", 17f); var attributedTitle = new NSAttributedString (title, font, UIColor.White, null, null, null, (NSLigatureType) 1, 0, (NSUnderlineStyle) 0, null, 0, NSUnderlineStyle.None); return attributedTitle; }
public NSAttributedString AttributedStringFor(NSObject value, NSDictionary attributes) { string match = StringFor(value); if (match == null) { return null; } NSMutableDictionary attDict = (NSMutableDictionary)attributes.MutableCopy(); attDict.LowlevelSetObject(value, NSStringAttributeKey.ForegroundColor.Handle); NSAttributedString atString = new NSAttributedString(match, attDict); return atString; }
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; }
public NSAttributedString ToAttributedString(UIFont baseFont) { if (_asAttributedString == null) { CTStringAttributes attrs = new CTStringAttributes (); attrs.Font = new CTFont(baseFont.Name, baseFont.PointSize); attrs.ForegroundColor = UIColor.Black.CGColor; _asAttributedString = IterateChildNodes (Definition, attrs); } return _asAttributedString; }
private void CustomTransParentButton(UIButton navigateButton) { navigateButton.Layer.BorderWidth = 2.0f; var highlightedAttributedTitle = new NSAttributedString("Get Movies", foregroundColor: UIColor.LightGray); navigateButton.SetAttributedTitle(highlightedAttributedTitle, UIControlState.Highlighted); navigateButton.TintColor = UIColor.Red; navigateButton.Frame = new CGRect((System.nfloat)startX, (System.nfloat)(startY + 4 * height), this.View.Bounds.Width - 2 * startX, height); navigateButton.SetTitle("Get Movies", UIControlState.Normal); navigateButton.SetTitleColor(UIColor.LightGray, UIControlState.Normal); navigateButton.TitleLabel.Font = UIFont.FromName("Helvetica", 18f); navigateButton.TitleLabel.TextColor = UIColor.LightGray; navigateButton.Layer.BackgroundColor = UIColor.Black.ColorWithAlpha(0.7f).CGColor; }
public override CGRect DrawTitle(NSAttributedString title, CGRect frame, NSView controlView) { if (TextColor != null) { var newtitle = (NSMutableAttributedString)title.MutableCopy(); var range = new NSRange(0, (int)title.Length); newtitle.RemoveAttribute(NSStringAttributeKey.ForegroundColor, range); newtitle.AddAttribute(NSStringAttributeKey.ForegroundColor, TextColor, range); title = newtitle; } var rect = base.DrawTitle(title, frame, controlView); return(rect); }
public override System.Drawing.RectangleF DrawTitle(NSAttributedString title, System.Drawing.RectangleF frame, NSView controlView) { if (TextColor != null) { var newtitle = title.MutableCopy() as NSMutableAttributedString; var range = new NSRange(0, title.Length); newtitle.RemoveAttribute(NSAttributedString.ForegroundColorAttributeName, range); newtitle.AddAttribute(NSAttributedString.ForegroundColorAttributeName, TextColor, range); title = newtitle; } var rect = base.DrawTitle(title, frame, controlView); return(rect); }
void ConfigureTextView() { TextView.Font = UIFont.FromDescriptor(UIFontDescriptor.PreferredBody, 0); TextView.TextColor = UIColor.Black; TextView.BackgroundColor = UIColor.White; TextView.ScrollEnabled = true; // Let's modify some of the attributes of the attributed string. // You can modify these attributes yourself to get a better feel for what they do. // Note that the initial text is visible in the storyboard. var attributedText = new NSMutableAttributedString(TextView.AttributedText); // Use NSString so the result of rangeOfString is an NSRange, not Range<String.Index>. var text = (NSString)TextView.Text; // Find the range of each element to modify. var boldRange = CalcRangeFor(text, "bold".Localize()); var highlightedRange = CalcRangeFor(text, "highlighted".Localize()); var underlinedRange = CalcRangeFor(text, "underlined".Localize()); var tintedRange = CalcRangeFor(text, "tinted".Localize()); // Add bold. Take the current font descriptor and create a new font descriptor with an additional bold trait. var boldFontDescriptor = TextView.Font.FontDescriptor.CreateWithTraits(UIFontDescriptorSymbolicTraits.Bold); var boldFont = UIFont.FromDescriptor(boldFontDescriptor, 0); attributedText.AddAttribute(UIStringAttributeKey.Font, boldFont, boldRange); // Add highlight. attributedText.AddAttribute(UIStringAttributeKey.BackgroundColor, ApplicationColors.Green, highlightedRange); // Add underline. attributedText.AddAttribute(UIStringAttributeKey.UnderlineStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), underlinedRange); // Add tint. attributedText.AddAttribute(UIStringAttributeKey.ForegroundColor, ApplicationColors.Blue, tintedRange); // Add image attachment. var img = UIImage.FromBundle("text_view_attachment"); var textAttachment = new NSTextAttachment { Image = img, Bounds = new CGRect(PointF.Empty, img.Size), }; var textAttachmentString = NSAttributedString.CreateFrom(textAttachment); attributedText.Append(textAttachmentString); TextView.AttributedText = attributedText; }
public void UIKitAttachmentConveniences_New() { if (!TestRuntime.CheckSystemAndSDKVersion(7, 0)) { Assert.Inconclusive("requires iOS7+"); } // so we added custom code calling the (old) category helper - but we had to pick a different name using (var ta = new NSTextAttachment(null, null)) using (var as2 = NSAttributedString.FromAttachment(ta)) { Assert.That(as2.Length, Is.EqualTo((nint)1), "Length"); Assert.That(as2.Value [0], Is.EqualTo((char)0xFFFC), "NSAttachmentCharacter"); } }
private void prepareForgotPasswordButton() { var boldFont = UIFont.SystemFontOfSize(12, UIFontWeight.Medium); var color = Core.UI.Helper.Colors.Login.ForgotPassword.ToNativeColor(); var text = new NSMutableAttributedString( Resources.LoginForgotPassword, foregroundColor: color); var boldText = new NSAttributedString( Resources.LoginGetHelpLoggingIn, foregroundColor: color, font: boldFont); text.Append(boldText); ForgotPasswordButton.SetAttributedTitle(text, UIControlState.Normal); }
protected override void OnAttached() { var entry = Control as UITextField; if (entry == null || string.IsNullOrWhiteSpace(entry.Placeholder)) { return; } old = entry.AttributedPlaceholder; var entryFontSize = entry.Font.PointSize; entry.AttributedPlaceholder = new NSAttributedString(entry.Placeholder, font: UIFont.ItalicSystemFontOfSize(entryFontSize)); }
private static NSAttributedString createAttributedString( IEnumerable <TokenTextAttachment> tagTokens) { var tagTokenString = tagTokens.Aggregate( new NSMutableAttributedString(), (result, token) => { result.Append(NSAttributedString.FromAttachment(token)); return(result); } ); return(tagTokenString); }
/// <summary> /// Sets the color of the placeholder text. /// </summary> /// <param name="view">The view.</param> void SetPlaceholderTextColor(RestaurantEntry view) { /* * UIColor *color = [UIColor lightTextColor]; * YOURTEXTFIELD.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"PlaceHolder Text" attributes:@{NSForegroundColorAttributeName: color}]; */ if (string.IsNullOrEmpty(view.Placeholder) == false && view.PlaceholderTextColor != Color.Default) { NSAttributedString placeholderString = new NSAttributedString(view.Placeholder, new UIStringAttributes { ForegroundColor = view.PlaceholderTextColor.ToUIColor() }); Control.AttributedPlaceholder = placeholderString; } }
public static void SetAttributedString(this NSTextView view, NSAttributedString str, bool canOverrideTextColor) { var textColor = view.TextColor; view.TextStorage.SetString(str); // Workaround: // Apply the previous view's TextColor, // otherwise it would be reset to Black by the line above. if (canOverrideTextColor && textColor != null) { view.TextColor = textColor; } }
private static NSMutableAttributedString AsAttributedString(this TagSpan tagSpan) { var tagName = new NSMutableAttributedString(tagSpan.TagName.TruncatedAt(maxTextLength), tagAttributes); var textAttachment = new TagTextAttachment(tagName, textVerticalOffset, regularFont.Descender); var tokenString = new NSMutableAttributedString(NSAttributedString.FromAttachment(textAttachment)); var attributes = createBasicAttributes(); attributes.Dictionary[TagId] = new NSNumber(tagSpan.TagId); attributes.Dictionary[TagName] = new NSString(tagSpan.TagName); tokenString.AddAttributes(attributes, new NSRange(0, tokenString.Length)); return(tokenString); }
/// <summary> /// The on element changed callback. /// </summary> /// <param name="e">The event arguments.</param> protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); var textField = Control; //Entry Styling //Padding textField.BorderStyle = UITextBorderStyle.Line; var paddingView = new UIView(new RectangleF(0, 0, 7, 20)); textField.LeftView = paddingView; textField.LeftViewMode = UITextFieldViewMode.Always; //Border textField.Layer.BorderWidth = 1; textField.Layer.CornerRadius = 4; textField.Layer.BorderColor = UIColor.FromRGB(202, 223, 233).CGColor; //Colors textField.Layer.BackgroundColor = UIColor.FromRGBA(255, 255, 255, 20).CGColor; textField.TintColor = UIColor.FromCGColor(Color.Transparent.ToCGColor()); //Font size var fontSize = UIScreen.MainScreen.Bounds.Width > 500.0 ? 35 : 24; textField.Font = UIFont.FromName("Arial", fontSize); if (string.IsNullOrEmpty(textField.Placeholder) == false) { var placeholderString = new NSAttributedString(textField.Placeholder, new UIStringAttributes { ForegroundColor = UIColor.FromRGBA(255, 255, 255, 150) }); textField.AttributedPlaceholder = placeholderString; } //Show Done button if entry is last item in the form otherwise shows Next button //if (this.Element != null &&(this.Element as HACCPTemperatureEntry).IsLastItem) textField.ReturnKeyType = UIReturnKeyType.Done; //else // textField.ReturnKeyType = UIReturnKeyType.Next; //Show done button if keyboard is numeric if (Element != null && Element.Keyboard == Keyboard.Numeric) { AddDoneButton(); } }
/// <summary> /// Using HTML formating to style UILabel /// </summary> /// <param name="label"></param> /// <param name="rawText"></param> public static void InitLabelWithHTMLFormat(UILabel label, string rawText) { NSAttributedStringDocumentAttributes documentAttributes = new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.HTML }; documentAttributes.StringEncoding = NSStringEncoding.UTF8; NSError error = null; NSAttributedString attributedString = new NSAttributedString(NSData.FromString(rawText, NSStringEncoding.UTF8), documentAttributes, ref error); //Ensuring text is resiezed correctly when font size is increased InitLabekWithSpacingAndHTMLFormatting(label, FontType.FontRegular, attributedString, 1.28, 16, 22); label.TextColor = ColorHelper.TEXT_COLOR_ON_BACKGROUND; }
static nfloat HeightWrappedToWidth(string title, NSFont font) { NSAttributedString textAttrStr = new NSAttributedString(title, font); CGSize maxSize = new CGSize(PUBLICATION_LINT_WIDTH - 6 * 2, 1000); CGRect boundRect = textAttrStr.BoundingRectWithSize(maxSize, NSStringDrawingOptions.TruncatesLastVisibleLine | NSStringDrawingOptions.UsesLineFragmentOrigin | NSStringDrawingOptions.UsesFontLeading); //multiple of 17 nfloat stringHeight = boundRect.Height; return(stringHeight); }
public CTTypesetter(NSAttributedString value) { if (value == null) { throw ConstructorError.ArgumentNull(this, "value"); } Handle = CTTypesetterCreateWithAttributedString(value.Handle); if (Handle == IntPtr.Zero) { throw ConstructorError.Unknown(this); } }
private static NSMutableAttributedString AsAttributedString(this TagSpan tagSpan) { var tagName = tagSpan.TagName.TruncatedAt(maxTextLength); var textAttachment = tagName.GetTagToken(); var tokenString = new NSMutableAttributedString(NSAttributedString.FromAttachment(textAttachment)); var attributes = createBasicAttributes(); attributes.Dictionary[TagId] = new NSNumber(tagSpan.TagId); attributes.Dictionary[TagName] = new NSString(tagSpan.TagName); tokenString.AddAttributes(attributes, new NSRange(0, tokenString.Length)); return(tokenString); }
void UpdateText() { var color = Element.TextColor; if (color == Color.Default) { Control.Title = Element.Text ?? ""; } else { var textWithColor = new NSAttributedString(Element.Text ?? "", foregroundColor: color.ToNSColor()); Control.AttributedTitle = textWithColor; } }
private void UpdateUi(cxEntry view) { try{ if (view.FontSize > 0) { this.Control.Font = UIFont.FromName(this.Control.Font.Name, (float)view.FontSize); } if (!string.IsNullOrEmpty(view.FontFamily)) { var fontName = Path.GetFileNameWithoutExtension(view.FontFamily); var font = UIFont.FromName(fontName, this.Control.Font.PointSize); if (font != null) { this.Control.Font = font; } } if (string.IsNullOrEmpty(view.Placeholder) == false && view.PlaceholderTextColor != Color.Default) { NSAttributedString placeholderString = new NSAttributedString(view.Placeholder, new UIStringAttributes() { ForegroundColor = view.PlaceholderTextColor.ToUIColor() }); this.Control.AttributedPlaceholder = placeholderString; } switch (view.Alignment) { case TextAlignment.Center: Control.TextAlignment = UITextAlignment.Center; break; case TextAlignment.End: Control.TextAlignment = UITextAlignment.Right; break; case TextAlignment.Start: Control.TextAlignment = UITextAlignment.Left; break; } } catch (System.Exception ex) { Insights.Send("UpdateUi", ex); } }
private static Tuple <NSMutableAttributedString, List <NewsCellView.Link> > CreateAttributedStringFromBlocks(UIFont font, UIColor primaryColor, IEnumerable <TextBlock> blocks) { var attributedString = new NSMutableAttributedString(); var links = new List <NewsCellView.Link>(); nint lengthCounter = 0; int i = 0; CoreText.CTFont ctFont; try { ctFont = new CoreText.CTFont(font.FamilyName, font.PointSize); } catch { ctFont = CGFont.CreateWithFontName(font.Name).ToCTFont(font.PointSize); } foreach (var b in blocks) { UIColor color = null; if (b.Tapped != null) { color = LinkColor; } color = color ?? primaryColor; var str = new NSAttributedString(b.Value, new CoreText.CTStringAttributes() { ForegroundColor = color.CGColor, Font = ctFont }); attributedString.Append(str); var strLength = str.Length; if (b.Tapped != null) { var weakTapped = new WeakReference <Action>(b.Tapped); links.Add(new NewsCellView.Link { Range = new NSRange(lengthCounter, strLength), Callback = () => weakTapped.Get()?.Invoke(), Id = i++ }); } lengthCounter += strLength; } return(new Tuple <NSMutableAttributedString, List <NewsCellView.Link> >(attributedString, links)); }
public NSAttributedString AttributedStringFor(NSObject value, NSDictionary attributes) { string match = StringFor(value); if (match == null) { return(null); } NSMutableDictionary attDict = (NSMutableDictionary)attributes.MutableCopy(); attDict.LowlevelSetObject(value, NSStringAttributeKey.ForegroundColor.Handle); NSAttributedString atString = new NSAttributedString(match, attDict); return(atString); }
public override void WindowDidLoad() { Window.BackgroundColor = NSColor.White; ContentTextView.EnclosingScrollView.BorderType = NSBorderType.NoBorder; base.WindowDidLoad(); Window.Title = "Teams and Conditions"; string filePath = NSBundle.MainBundle.PathForResource("/Images/Setting/Termsandconditions", "doc"); NSData fileData = NSData.FromFile(filePath); NSDictionary docAttributeo = new NSDictionary(); var content = new NSAttributedString(fileData, out docAttributeo); //var newContent = new NSAttributedString (SettingsUtil.Instance.GetTermsAndConditions ()); ContentTextView.TextStorage.SetString(content); }
void SetPlaceholderColor(PickerView picker) { string placeholderColor = picker.PlaceholderColor; UIColor color = UIColor.FromRGB(GetRed(placeholderColor), GetGreen(placeholderColor), GetBlue(placeholderColor)); var placeholderAttributes = new NSAttributedString(picker.Title, new UIStringAttributes() { ForegroundColor = color }); if (Control != null) { Control.AttributedPlaceholder = placeholderAttributes; } }
protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (Control == null) { return; } var title = new NSAttributedString(Control.CurrentTitle, new UIStringAttributes { ForegroundColor = DisabledColor }); Control.SetAttributedTitle(title, UIControlState.Disabled); }
void SetTextColor(ExtendedEntry view) { try { NSAttributedString TextString = new NSAttributedString(view.Text, new UIStringAttributes() { ForegroundColor = view.TextColor.ToUIColor() }); Control.AttributedText = TextString; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
public static NSButton CreateClickableLabel(CGRect rect, NSFont font, NSAttributedString text) { var label = new NSButton(rect) { AttributedTitle = text, BezelStyle = NSBezelStyle.Inline, Bordered = false, Font = font, ImagePosition = NSCellImagePosition.ImageLeft, TranslatesAutoresizingMaskIntoConstraints = false }; label.SetButtonType(NSButtonType.MomentaryPushIn); return(label); }
protected virtual void SetupResendCodeButton(UIButton button) { button.SetupStyle(ThemeConfig.TextButton); var paragraphStyle = new NSMutableParagraphStyle(); paragraphStyle.Alignment = UITextAlignment.Center; var resendTitle = new NSAttributedString(LocalizationService.GetLocalizableString(AuthConst.RESX_NAME, "Password_Sms_SentAgain"), font: (UIFont)ThemeConfig.TextButton.Font, foregroundColor: button.TitleLabel.TextColor, paragraphStyle: paragraphStyle); button.WithAttributedTitleForAllStates(resendTitle); }
public CTTypesetter(NSAttributedString value, CTTypesetterOptions options) { if (value == null) { throw ConstructorError.ArgumentNull(this, "value"); } handle = CTTypesetterCreateWithAttributedStringAndOptions(value.Handle, options == null ? IntPtr.Zero : options.Dictionary.Handle); if (handle == IntPtr.Zero) { throw ConstructorError.Unknown(this); } }
void UpdateCancelButton() { var cancelButtonColor = Element.CancelButtonColor; if (cancelButtonColor.IsDefault) { Control.Cell.CancelButtonCell.Title = ""; } else { var textWithColor = new NSAttributedString(Control.Cell.CancelButtonCell.Title ?? "", foregroundColor: cancelButtonColor.ToNSColor()); Control.Cell.CancelButtonCell.AttributedTitle = textWithColor; } }
/// <summary> /// Creates an NSAttibutedString html string using the custom tags for styling. /// </summary> /// <returns>NSAttibutedString</returns> /// <param name="text">Text to display including html tags</param> /// <param name="customTags">A list of custom <c>CSSTagStyle</c> instances that set the styling for the html</param> /// <param name="useExistingStyles">Existing CSS styles willl be used If set to <c>true</c></param> public NSAttributedString CreateHtmlString(string text, List <CssTag> customTags = null, bool useExistingStyles = true) { var error = new NSError(); text = HtmlTextStyleParser.StyleString(text, _textStyles, customTags, useExistingStyles); var stringAttribs = new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.HTML, StringEncoding = NSStringEncoding.UTF8 }; var htmlString = new NSAttributedString(text, stringAttribs, ref error); return(htmlString); }
/// <summary> /// Adds Accessibility label on the label using the raw text containing html /// </summary> /// <param name="label"></param> /// <param name="rawText"></param> public static void InitLabelAccessibilityTextWithHTMLFormat(UILabel label, string rawText) { //Defining attibutes inorder to format the embedded link NSAttributedStringDocumentAttributes documentAttributes = new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.HTML }; documentAttributes.StringEncoding = NSStringEncoding.UTF8; NSError error = null; NSAttributedString attributedString = new NSAttributedString(NSData.FromString(rawText, NSStringEncoding.UTF8), documentAttributes, ref error); NSMutableAttributedString text = new NSMutableAttributedString(attributedString); label.AccessibilityAttributedLabel = text; }
public static UILabel LabelForTitle(string title) { var TitleView = new UILabel { BackgroundColor = UIColor.Clear, Font = UIFont.FromName ("Montserrat-Bold", 17.5f), Frame = new RectangleF (0, 0, 0, 0), Text = title.ToUpper (), TextColor = UIColor.White }; TitleView.SizeToFit (); var str = new NSAttributedString (title, new CTStringAttributes () { KerningAdjustment = 1.5f }); TitleView.AttributedText = str; return TitleView; }
public NSAttributedString AttributedStringForParagraph (XElement paragraph) { var returnValue = new NSMutableAttributedString (); // TODO: find stage directions and format them differently if (ParagraphIsStageDirection (paragraph)) { var stageDirection = new NSAttributedString (TextForParagraph (paragraph), font: UIFont.FromName ("Helvetica-LightOblique", 24), paragraphStyle: new NSMutableParagraphStyle () { Alignment = UITextAlignment.Center, LineSpacing = 10}); returnValue.Append (stageDirection); } else { var speaker = new NSAttributedString (SpeakerForParagraph (paragraph), font: UIFont.FromName ("HoeflerText-Black", 24), foregroundColor: UIColor.Brown ); var text = new NSAttributedString (TextForParagraph (paragraph), font: UIFont.FromName ("HoeflerText-Regular", 24.0f), foregroundColor: UIColor.Black #if TEST_OTHER_ATTRIBUTES ,backgroundColor: UIColor.Yellow, ligatures: NSLigatureType.None, kerning: 10, underlineStyle: NSUnderlineStyle.Single, shadow: new NSShadow () { ShadowColor = UIColor.Red, ShadowOffset = new System.Drawing.SizeF (5, 5) }, strokeWidth: 5 #endif ); returnValue.Append (speaker, " ", text); } if (Paragraphs.IndexOf (paragraph) == SelectedParagraph) { returnValue.AddAttribute (UIStringAttributeKey.ForegroundColor, UIColor.White, new NSRange (0, returnValue.Length)); returnValue.AddAttribute (UIStringAttributeKey.BackgroundColor, UIColor.FromHSB (.6f, .6f, .7f), new NSRange (0, returnValue.Length)); } returnValue.EnumerateAttribute (UIStringAttributeKey.ParagraphStyle, new NSRange (0, returnValue.Length), NSAttributedStringEnumeration.LongestEffectiveRangeNotRequired, (NSObject value, NSRange range, ref bool stop) => { var style = value == null ? new NSMutableParagraphStyle () : (NSMutableParagraphStyle)value.MutableCopy (); style.MinimumLineHeight = LineHeight; style.MaximumLineHeight = LineHeight; returnValue.AddAttribute (UIStringAttributeKey.ParagraphStyle, style, range); }); return returnValue; }
public static UIImage ToUIImage(this IIcon icon, nfloat size) { var attributedString = new NSAttributedString($"{icon.Character}", new CTStringAttributes { Font = new CTFont(Iconize.FindModuleOf(icon).FontName, size), ForegroundColorFromContext = true }); var boundSize = attributedString.GetBoundingRect(new CGSize(10000, 10000), NSStringDrawingOptions.UsesLineFragmentOrigin, null).Size; UIGraphics.BeginImageContextWithOptions(boundSize, false, 0f); attributedString.DrawString(new CGRect(0, 0, boundSize.Width, boundSize.Height)); var image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); return image; }
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; }
public LabelDetailController() { coloredLabel.SetTextColor (UIColor.Purple); var attrString = new NSAttributedString ("Ultralight Label", new UIStringAttributes { Font = UIFont.SystemFontOfSize (16f, UIFontWeight.UltraLight) }); ultralightLabel.SetText (attrString); var components = new NSDateComponents { Day = 10, Month = 12, Year = 2015 }; timer.SetDate (NSCalendar.CurrentCalendar.DateFromComponents (components)); timer.Start (); }
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 void Awake(NSObject context) { base.Awake(context); _wormHole = new Wormhole (AppSettings.iOSAppGroupIdentifier, AppSettings.iOSAppGroupDirectory); _wormHole.ListenForMessage<NextPillsMessage> (NextPillsMessage.MessageType, UpdateUI); var waitingAttrString = new NSAttributedString("Please, open Patients on your iPhone", new UIStringAttributes { Font = UIFont.SystemFontOfSize(14, UIFontWeight.Light) }); waitingLabel.SetText(waitingAttrString); var nextInAttrString = new NSAttributedString("Next", new UIStringAttributes { Font = UIFont.SystemFontOfSize(14, UIFontWeight.Medium) }); nextInLabel.SetText(nextInAttrString); ToggleUI(true); }
public DetailViewController(RSSFeedItem item) : base(UITableViewStyle.Grouped, null, true) { var attributes = new NSAttributedStringDocumentAttributes(); attributes.DocumentType = NSDocumentType.HTML; attributes.StringEncoding = NSStringEncoding.UTF8; var error = new NSError(); var htmlString = new NSAttributedString(item.Description, attributes, ref error); Root = new RootElement(item.Title) { new Section{ new StringElement(item.Author), new StringElement(item.PublishDate), new StyledMultilineElement(htmlString), new HtmlElement("Full Article", item.Link) } }; }
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; }
private float HeightOfText(string text,int width) { UIFont font = UIFont.SystemFontOfSize(15.0f); NSMutableParagraphStyle paragraphStyle = new NSMutableParagraphStyle(); paragraphStyle.LineBreakMode = UILineBreakMode.WordWrap; NSMutableDictionary attributes = new NSMutableDictionary(); attributes[UIStringAttributeKey.Font] = font; attributes[UIStringAttributeKey.ParagraphStyle] = paragraphStyle; NSAttributedString attributedText = new NSAttributedString (text, attributes); RectangleF paragraphRect = attributedText.GetBoundingRect( new System.Drawing.SizeF(width, float.MaxValue), NSStringDrawingOptions.UsesLineFragmentOrigin, null); return paragraphRect.Height; }
protected override void OnElementChanged(ElementChangedEventArgs<Label> e) { base.OnElementChanged (e); if (e.NewElement != null) { var element = (HtmlView)e.NewElement; if (element.Text != null) { NSError error = null; var attributedString = new NSAttributedString (NSData.FromString (e.NewElement.Text), new NSAttributedStringDocumentAttributes { DocumentType = NSDocumentType.HTML }, ref error); this.Control.AttributedText = attributedString; this.Control.TextColor = UIColor.White; this.Control.Font = UIFont.FromName ("Orbitron", 16); this.Control.AdjustsFontSizeToFitWidth = true; } } }
public static NSAttributedString ToAttributedString(this PriceMovement priceMovement, IPrice price) { if (price == null) { return new NSAttributedString(string.Empty); } var movementText = new Dictionary<PriceMovement, NSAttributedString> { {PriceMovement.Up, new NSAttributedString("▲", _arrowFont, UIColor.Green) }, {PriceMovement.Down, new NSAttributedString("▼", _arrowFont, UIColor.Red) }, {PriceMovement.None, new NSAttributedString("▼", _arrowFont, UIColor.Clear) } }; var spread = new NSAttributedString(price.Spread.ToString("0.0") + " "); var text = new NSMutableAttributedString(spread); text.Append(movementText[priceMovement]); return text; }
public void BindDataToView(string nickname, string bio){ if (!String.IsNullOrEmpty (nickname)) { NSMutableAttributedString attributedString = new NSMutableAttributedString (nickname); attributedString.BeginEditing (); attributedString.AddAttribute (UIStringAttributeKey.Font, UIFont.BoldSystemFontOfSize(14), new NSRange (0, attributedString.Value.Length)); if(!String.IsNullOrEmpty(bio)){ var test = attributedString.Length; attributedString.Append(new NSAttributedString ("\n")); attributedString.Append(new NSAttributedString(bio)); attributedString.AddAttribute (UIStringAttributeKey.Font, UIFont.SystemFontOfSize(14), new NSRange (test, attributedString.Value.Length - test)); } attributedString.AddAttribute (UIStringAttributeKey.ForegroundColor, UIColor.FromRGB (129, 132, 136), new NSRange (0, attributedString.Value.Length)); AttributedText = attributedString; } else if(!String.IsNullOrEmpty(bio)){ NSMutableAttributedString attributedString = new NSMutableAttributedString (""); attributedString.Append(new NSAttributedString(bio)); attributedString.AddAttribute (UIStringAttributeKey.Font, UIFont.SystemFontOfSize (14), new NSRange (0, attributedString.Value.Length)); attributedString.AddAttribute (UIStringAttributeKey.ForegroundColor, UIColor.FromRGB (129, 132, 136), new NSRange (0, attributedString.Value.Length)); AttributedText = new NSAttributedString (attributedString); } }
void DrawTexts(List<string> tagStrings, List<RectangleF> rects) { using (CGContext gctx = UIGraphics.GetCurrentContext ()) { gctx.SaveState (); gctx.ScaleCTM (1f, -1f); gctx.TranslateCTM (0, Frame.Height); gctx.SetFillColor (UIColor.Green.CGColor); for (int i = 0; i < tagStrings.Count; i++) { gctx.SaveState (); var attributedString = new NSAttributedString (tagStrings[i], new CTStringAttributes { ForegroundColorFromContext = true, Font = new CTFont ("ArialMT", 48) }); gctx.TextPosition = new PointF (rects[i].X, rects[i].Y); using (var textLine = new CTLine (attributedString)) { textLine.Draw (gctx); } gctx.RestoreState (); } gctx.RestoreState (); } }
public override void Draw(CGRect rect) { base.Draw (rect); var gctx = UIGraphics.GetCurrentContext (); gctx.TranslateCTM (10, 0.5f * Bounds.Height); gctx.ScaleCTM (1, -1); gctx.RotateCTM ((float)Math.PI * 315 / 180); gctx.SetFillColor (UIColor.Green.CGColor); string someText = "你好世界"; var attributedString = new NSAttributedString (someText, new CTStringAttributes{ ForegroundColorFromContext = true, Font = new CTFont ("Arial", 24) }); using (var textLine = new CTLine (attributedString)) { textLine.Draw (gctx); } }
private NSAttributedString GetAttributedTitle (UIPickerView pickerView, int row, int component) { float colorValue = row * RGB.offset; float value = colorValue / RGB.max; float redColorComponent = RGB.min; float greenColorComponent = RGB.min; float blueColorComponent = RGB.min; switch( (ColorComponent)component) { case ColorComponent.Red: redColorComponent = value; break; case ColorComponent.Green: greenColorComponent = value; break; case ColorComponent.Blue: blueColorComponent = value; break; default: throw new InvalidOperationException ("Invalid row/component combination for picker view."); } UIColor foregroundColor = new UIColor (redColorComponent, greenColorComponent, blueColorComponent, alpha: 1f); // Set the foreground color for the entire attributed string. UIStringAttributes attributes = new UIStringAttributes { ForegroundColor = foregroundColor }; var title = new NSAttributedString (string.Format ("{0}", (int)colorValue), attributes); return title; }