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 に答える