なんか作る&なんかする

蓄財とあらゆる保守管理の備忘録

UIRefreshControlに文字を出したり文字に色をつけたり。

引っ張って更新とかで使うやつ。

UIRefreshControlのattributedTitleにNSAttributedStringとかNSMutableAttributedStringで作ったのをいれます。

UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];

NSAttributedString*attstr
=[[NSMutableAttributedString alloc]
  initWithString:NSLocalizedString(@"Loading...", nil)
  attributes:@{
    NSForegroundColorAttributeName:[UIColor colorWithRed:0.32 green:0.46 blue:0.54 alpha:1],
    NSFontAttributeName:[UIFont boldSystemFontOfSize:13.0f]
}];

refreshControl.attributedTitle = attstr;
self.refreshControl = refreshControl;

(改行いれたら微妙かな…)

 表示したいテキストが Loading... のローカライズ、テキストの色はUIColorで指定、フォントは太文字の13.0fとか。
 attributes に NSDictionaryで設定する。中括弧の {キー:値,キー:値} の形式は最近本当に多い。こればっかり。