Xamarin.Mac中的NSAttributeString

时间:2015-06-02 08:28:41

标签: c# macos xamarin nsattributedstring xamarin.mac

我正在使用xamarin.mac

实际上根据要求,我需要显示NSString,如下所示,请你帮助我。

我在Font的帮助下成功应用了ColorNSAttributeString但是找不到申请方式link Attribute

enter image1 description here

参考: using-label-as-a-hyperlink

NSMutableAttributedString attrStr = new NSMutableAttributedString("My cool hyperlink");

var range = new NSRange(8, 9); // Range for "hyperlink" word
var url = new NSUrl("http://google.com/");
var font = _myLablel.Font; // _myLablel is an instance of NSClickableURLTextField class

// We have to setup paragraph if we want to keep original alignment and line break node
var paragraph = new NSMutableParagraphStyle();
paragraph.LineBreakMode = _myLabel.Cell.LineBreakMode;
paragraph.Alignment = _myLabel.Alignment;

attrStr.BeginEditing();
    attrStr.AddAttribute(NSAttributedString.LinkAttributeName, url, range);
    attrStr.AddAttribute(NSAttributedString.ForegroundColorAttributeName, NSColor.Blue, range);
    attrStr.AddAttribute(NSAttributedString.UnderlineStyleAttributeName, new NSNumber(1), range);
    attrStr.AddAttribute(NSAttributedString.FontAttributeName, font, new NSRange(0, attrStr.Length)); // Set font for entire string
    attrStr.AddAttribute(NSAttributedString.ParagraphStyleAttributeName, paragraph, new NSRange(0, attrStr.Length)); // Optional
attrStr.EndEditing();

_myLabel.AttributedStringValue = attrStr;

问题如何获取hyperlink的活动?

感谢。 :)

0 个答案:

没有答案