2

https://github.com/TTTAttributedLabel/TTTAttributedLabelの Xamarin バインディングを使用しています

そして、以下のように - UILabel.attributedText でリンクを作成 *青色ではなく*下線付き *なし

self.label.linkAttributes = @{NSForegroundColorAttributeName: color, 
                               NSUnderlineStyleAttributeName: @(NSUnderlineStyleNone)};

リンク属性を設定したいのですが、構文がよくわかりません -

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/AttributedStrings/Articles/standardAttributes.html

私はこれらのバリエーションを試しました -

 label.LinkAttributes = new NSDictionary(
            new NSString("NSForegroundColorAttributeName"), UIColor.Red,
            new NSString("NSUnderlineStyleAttributeName"), new NSUnderlineStyle() == NSUnderlineStyle.Double);

 label.LinkAttributes = new NSDictionary(
            new NSString("NSForegroundColorAttributeName"), UIColor.Red,
            new NSString("NSUnderlineStyleAttributeName"), new NSNumber(2));

しかし、機能していません。使用可能な Type が表示されないため、UIColor を渡す方法がわからないため、このコードで下線 + 青色をワイプして「何か」を実行しています。

4

1 に答える 1

2

次のコード行は、リンクしたプロジェクトの github README.mdから取得したものです。

(id)kCTForegroundColorAttributeName : (id)[UIColor redColor].CGColor,

ライブラリが扱っているように見えますCGColorまたは UIColorOSXNSColorのみ)。色を表現する方法は (あまりにも) たくさんありますが、悲しいことに、ほとんどの API は 1 つの方法でしか機能しません。この場合、次を使用する必要があります。

UIColor.Red.CGColor

それ以外の:

UIColor.Red

LinkAttributesラベルのプロパティに与える辞書で。

キーkCTForegroundColorAttributeName(コメントから)は、定数の名前とは異なる場合があるAppleの定数値とも一致する必要があります。Xamarin.iOS では、この定数は次のように公開されます。

CoreText.CTStringAttributeKey.ForegroundColor

そのため、ライブラリが CoreText 定数を (再) 使用する場合、これが使用する値になります。

于 2015-12-21T20:49:05.440 に答える