Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underline text in UILabel in monotouch (porting ObjC code)

I would like to underline the text in a UILabel. I have found following code for ObjC:

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

I'm trying to port this to C# but it's not working. I'm trying the following:

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

Instead of 1, I also tried "1" and NSUnderlineStyle.Single, but nothing is working

Any ideas?

Thanks

like image 779
Matt Avatar asked Jan 14 '23 20:01

Matt


1 Answers

Try this:

label.AttributedText = new NSAttributedString (
    "Test", 
    underlineStyle: NSUnderlineStyle.Single);
like image 163
Rolf Bjarne Kvinge Avatar answered Jan 19 '23 11:01

Rolf Bjarne Kvinge