4

我想在 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,但没有任何效果

有任何想法吗?

谢谢

4

1 回答 1

9

尝试这个:

label.AttributedText = new NSAttributedString (
    "Test", 
    underlineStyle: NSUnderlineStyle.Single);
于 2013-03-26T18:10:32.803 回答