3

この投稿でNSAttributedStringの例を見つけました。私の質問は-何かヒントはありますか、それをどのように使用するのUIRefreshControl classですか?

上記の投稿から:

NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"firstsecondthird"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)];

属性はUIRefreshControl自動的に呼び出されますか?

編集:

私はそれを設定する方法を知っています、それが「ちょうど」フォーマットされたラベル以外の目的を果たしているかどうか知りたいです-UIRefresherControlは2つの文字列を表示できますか?引っ張られる前と引っ張られた後の1つ?それが、「普通の」文字列が入れられないのを見て最初に思ったものです。

4

2 に答える 2

5

これは、UIRefreshControl でティント カラー、フォント カラー、およびフォント スタイルを作成および変更する方法の完全な例です。

_refreshControl = [[UIRefreshControl alloc] init];
_refreshControl.tintColor = [UIColor blackColor];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"Pull to Refresh"];
NSRange fullRange = NSMakeRange(0, [string length]);
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:fullRange];
[string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Georgia" size:17] range:fullRange];
[_refreshControl setAttributedTitle:string];
[_refreshControl addTarget:self action:@selector(refresh:) forControlEvents:UIControlEventValueChanged];
[self setRefreshControl:_refreshControl];
于 2013-07-17T16:20:05.630 に答える
4

howが を受け取るプロパティをUIRefreshControl持ち、howが のサブクラスであることを確認すると、次のようになります。attributedTitleNSAttributedStringNSMutableAttributedStringNSAttributedString

[myRefreshControl setAttributedTitle:string];

UIRefresherControl は 2 つの文字列を表示できますか?

いいえ、できません。ただし、属性付きの文字列に複数の行を挿入したり、異なる段落スタイルを挿入したりすることはできます (たとえば、ある部分を左揃えにし、別の部分を右揃えにすることができます)。

引っ張る前と引っ張った後?

いいえ。独自のアプリケーションのロジックに従って、refreshControl の属性付きタイトルを変更するのはあなた次第です。

于 2012-10-19T14:33:24.770 に答える