我正在使用xamarin.mac
。
实际上根据要求,我需要显示NSString
,如下所示,请你帮助我。
我在Font
的帮助下成功应用了Color
,NSAttributeString
但是找不到申请方式link Attribute
参考: 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
的活动?
感谢。 :)