UIAlertViewで使われてるフォントを調べる
iOS7のUIAlertViewで使用されているラベル、ボタンラベルがどんなフォントを使っているのか知りたくなった。
以下のコードを使って確認する。
-(void)logUIAlertViewFont:(UIAlertView*)alertView { UILabel *title = [alertView valueForKey:@"_titleLabel"]; NSLog(@"%@ : %@", [title text], [[title font] description]); UILabel *body = [alertView valueForKey:@"_bodyTextLabel"]; NSLog(@"%@ : %@", [body text], [[body font] description]); NSMutableArray *buttons = (NSMutableArray*)[alertView valueForKey:@"_buttons"]; NSLog(@"%@ : %@", [[[buttons objectAtIndex:0] titleLabel ]text], [[[[buttons objectAtIndex:0] titleLabel ]font] description]); NSLog(@"%@ : %@", [[[buttons objectAtIndex:1] titleLabel ]text], [[[[buttons objectAtIndex:1] titleLabel ]font] description]); return; }
サンプルとして上記のようなUIAlertViewをこのメソッドにくれてあげる。
結果はこんな感じ
2013-10-02 21:41:43.145 WCTest[1555:a0b] Title : <UICTFont: 0x89a28a0> font-family: ".HelveticaNeueInterface-M3"; font-weight: normal; font-style: normal; font-size: 17.00pt 2013-10-02 21:41:43.147 WCTest[1555:a0b] Message : <UICTFont: 0x89a33b0> font-family: ".HelveticaNeueInterface-M3"; font-weight: normal; font-style: normal; font-size: 15.00pt 2013-10-02 21:41:43.148 WCTest[1555:a0b] Cancel : <UICTFont: 0x8c72a10> font-family: ".HelveticaNeueInterface-M3"; font-weight: normal; font-style: normal; font-size: 18.00pt 2013-10-02 21:41:43.149 WCTest[1555:a0b] other : <UICTFont: 0x8c72a10> font-family: ".HelveticaNeueInterface-M3"; font-weight: normal; font-style: normal; font-size: 18.00pt
フォントサイズは分かったのだけど、タイトルとデフォルトボタンのラベルが太字っぽくみえてるので
boldになってるものと思ったのだが、違うようですね。どうしてんだろ。