UIKit.UITextView.AttributedText Property
Contents of the text view as an attributed string.

Syntax

[ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.iOS_6_0)]
[get: Foundation.Export("attributedText")]
[get: ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.iOS_6_0)]
[set: Foundation.Export("setAttributedText:")]
[set: ObjCRuntime.Availability(Introduced=ObjCRuntime.Platform.iOS_6_0)]
public virtual Foundation.NSAttributedString AttributedText { get; set; }

See Also

UITextView.AllowsEditingTextAttributes
UITextView.DataDetectorTypes
UITextView.Editable
UITextView.Font
UITextView.Text
UITextView.TextAlignment
UITextView.TextContainerInsert
UITextView.TextColor
UITextView.TypingAttributes

Value

Remarks

Application developers must use this property if they desire the use of multiple text styles in the UIKit.UITextView. The following example uses Foundation.NSMutableAttributableString.AddAttribute to modify the color and font in a various ranges, as shown in the image.

C# Example

  //UITextView default
  var atts = new UIStringAttributes();
  atts.ForegroundColor = UIColor.Blue;
  var txt = "Text Kit.\n Lorem ipsum different font dolor sit amet, consectetur adipiscing elit.";
  var attributedString = new NSMutableAttributedString(txt,atts);
  
  //Multiple type styles. 
  attributedString.BeginEditing();
  attributedString.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.Red, new NSRange(0, 10));
  attributedString.AddAttribute(UIStringAttributeKey.Font, UIFont.PreferredFontForTextStyle(UIFontTextStyle.Headline), new NSRange(0, 10));
  attributedString.AddAttribute(UIStringAttributeKey.Font, UIFont.FromName("Georgia", 20), new NSRange(23, 14));
  attributedString.EndEditing();
  
  TextView.AttributedText = attributedString;
            

Requirements

Namespace: UIKit
Assembly: Xamarin.iOS (in Xamarin.iOS.dll)
Assembly Versions: 0.0.0.0