UILabel中的单字幕下划线文本(移植ObjC代码)

时间:2013-03-26 17:07:33

标签: ios xamarin.ios uilabel nsattributedstring

我想强调UILabel中的文字。 我找到了以下ObjC代码:

NSDictionary *underlineAttribute = @{NSUnderlineStyleAttributeName: @1}
myLabel.attributedText = [[NSAttributedString alloc] initWithString:@"Test string" 
                                                     attributes:underlineAttribute];

我正在尝试将其移植到C#,但它无法正常工作。 我正在尝试以下方法:

var keys = new object[] { "NSUnderlineStyleAttributeName" };
var objects = new object[] { 1 };
NSDictionary underlineAttribute = NSDictionary.FromObjectsAndKeys(objects, keys);
label.AttributedText = new NSAttributedString(@"Test",underlineAttribute);

而不是1,我也试过“1”和NSUnderlineStyle.Single,但没有任何工作

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:8)

试试这个:

label.AttributedText = new NSAttributedString (
    "Test", 
    underlineStyle: NSUnderlineStyle.Single);
相关问题