共用方式為


UITextView.AttributedText 屬性

定義

文字檢視的內容做為屬性字串。

[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

屬性值

屬性

備註

如果應用程式開發人員想要在 中使用 UITextView 多個文字樣式,則必須使用這個屬性。 下列範例會使用 M:Foundation.NSMutableAt配量String.AddAttribute*來修改各種範圍中的色彩和字型,如下圖所示。

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

適用於

另請參閱