Edit

Share via


UITextView.AttributedText Property

Definition

Contents of the text view as an attributed string.

[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 6, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public virtual Foundation.NSAttributedString AttributedText { [ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 6, 0, ObjCRuntime.PlatformArchitecture.All, null)] [Foundation.Export("attributedText", ObjCRuntime.ArgumentSemantic.Copy)] get; [ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 6, 0, ObjCRuntime.PlatformArchitecture.All, null)] [Foundation.Export("setAttributedText:", ObjCRuntime.ArgumentSemantic.Copy)] set; }
member this.AttributedText : Foundation.NSAttributedString with get, set

Property Value

Attributes

Remarks

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

//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;

Applies to

See also