XcodeのUIFontで指定できるフォント一覧(日本語付き)
↓こちらでも紹介されているのですが、日本語がなかったのでxcodeで実装して見た。
http://iphone-dev.g.hatena.ne.jp/tokorom/20090912/1252769688
A
A-B
B-C
C-E
F-G
G-H
H-K
M-O
P-T
T-Z
以下、実装メモ
※storyboardでTableViewを入れ、Controllerをつなげています。
・TestViewController.h
#import <UIKit/UIKit.h>
@interface TestViewController : UITableViewController <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *testTable;
@property (strong, nonatomic) NSArray *fontList;
@property (strong, nonatomic) NSMutableDictionary *fontNames;
@end
・TestViewController.m
#import "TestViewController.h"
@interface TestViewController ()
@end
@implementation TestViewController
@synthesize testTable;
@synthesize fontList;
@synthesize fontNames;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.fontNames = [NSMutableDictionary dictionary];
self.fontList = [[UIFont familyNames] sortedArrayUsingSelector:@selector(compare:)];
for (int i = 0; i < [fontList count]; i++) {
// oya
NSString *fontName = [fontList objectAtIndex:i];
NSArray *childFonts = [[UIFont fontNamesForFamilyName:fontName] sortedArrayUsingSelector:@selector(compare:)];
[self.fontNames setObject:childFonts forKey:[NSNumber numberWithInt:i]];
}
// フォント一覧をログ出力 NSLog(@"%@", self.fontList);
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
// セクション数を返す
-(NSInteger)numberOfSectionsInTableView:
(UITableView *)tableView {
NSLog(@"section=%d", self.fontList.count);
return self.fontList.count;
}
// 各セクションのタイトルを返す
-(NSString *)tableView:
(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section {
return [fontList objectAtIndex:section];
}
// セクションに含まれるセル数を返す
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return self.fontNames objectForKey:[NSNumber numberWithInt:section count];
}
// セルの内容を返す
-(UITableViewCell *)tableView:
(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSString *cellFontName = self.fontNames objectForKey:[NSNumber numberWithInt:indexPath.section objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat: @"あいう漢字カタカナ123123ABCabc (%@)", cellFontName];
cell.textLabel.font = [UIFont fontWithName:cellFontName size:16];
return cell;
}
@end