我在Objetive-C中使用了这段代码:
static NSString *const kTableFooterHTMLFormatString = @"<html><head><style type='text/css'>body{font-family: '-apple-system','HelveticaNeue';font-size:14;text-align:center;color:#3a3a3a;-webkit-user-select:none;-webkit-touch-callout:none;}a{text-decoration:none;color:#0b51b0;}</style><meta charset='UTF-8'></head><body>Copyright ©%@ Company name. <br/> <a href='%@/privacy.do'>Privacy Policy</a> & <a href='%@/termsOfUse.do'>Terms of Use</a></body></html>";
_tableFooterVC.htmlString = [NSString stringWithFormat:kTableFooterHTMLFormatString, [[NSDate date] yearString], currentBaseURLString, currentBaseURLString];
Xamarin中的等价物是什么?
我在其他Xamarin帖子上发现了这个,但它丢失了字体,并且格式化:
var htmlLink = String.Format("<html><head><meta charset='UTF-8'></head><body>Copyright ©{0} Company name. <br /><a href='{1}/privacy.do'>Privacy Policy</a> & <a href='{2}/termsOfUse.do'>Terms of Use</a></body></html>", "2016", "http://www.company.com", "http://www.company.com");
this.TermsLabel.AttributedText = new NSAttributedString(htmlLink, attr, ref nsError);
问题的第2部分,我也需要UITESTS可以链接的链接。所以,我需要id或者引用测试的URL。
答案 0 :(得分:1)
UILabel
不支持可点击链接,因此我假设您的自定义TermsLabel
中的UITableViewHeaderFooterView
是可选择的不可编辑的UITextView
。
设置包含AttributedText
的{{1}}:
html
注意: iOS HTML转换器只应在主/ UI线程上使用。
答案 1 :(得分:0)
在Xamarin,
您可以使用以下代码安静。
NSAttributedStringDocumentAttributes attr = new NSAttributedStringDocumentAttributes();
attr.DocumentType = NSDocumentType.HTML;
NSError err = new NSError();
NSAttributedString messageString = new NSAttributedString(NSData.FromString(model.TaskDescription), attr, ref err);
ActivityDescription.AttributedText = messageString;
此处,活动描述是我的TextView