标签:
效果如下:
ViewController.h
1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UITableViewController 4 @property (strong, nonatomic) NSMutableDictionary *mDicFontName; 5 @property (strong, nonatomic) NSArray *arrFamilyName; 6 7 @end
ViewController.m
1 #import "ViewController.h" 2 3 @interface ViewController () 4 @end 5 6 @implementation ViewController 7 8 - (void)viewDidLoad { 9 [super viewDidLoad]; 10 } 11 12 - (void)didReceiveMemoryWarning { 13 [super didReceiveMemoryWarning]; 14 // Dispose of any resources that can be recreated. 15 } 16 17 - (id)init { 18 if (self = [super initWithStyle:UITableViewStyleGrouped]) { 19 self.title = @"Menu"; 20 if (!_mDicFontName) { 21 _mDicFontName = [[NSMutableDictionary alloc] initWithCapacity:32]; 22 _arrFamilyName = [[UIFont familyNames] sortedArrayUsingSelector:@selector(compare:)]; 23 24 for (id familyName in _arrFamilyName) { 25 NSArray *arrFont = [UIFont fontNamesForFamilyName:familyName]; 26 NSLog(@"%@", [arrFont description]); 27 [_mDicFontName setObject:arrFont forKey:familyName]; 28 } 29 } 30 } 31 return self; 32 } 33 34 #pragma mark - UITableView methods 35 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 36 return [_arrFamilyName count]; 37 } 38 39 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 40 NSString *familyName = [_arrFamilyName objectAtIndex:section]; 41 return [[_mDicFontName objectForKey:familyName] count]; 42 } 43 44 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 45 static NSString *cellIdentifier = @"cell"; 46 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 47 if (!cell) { 48 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 49 } 50 51 NSString *familyName = [_arrFamilyName objectAtIndex:indexPath.section]; 52 NSString *fontName = [[_mDicFontName objectForKey:familyName] objectAtIndex:indexPath.row]; 53 cell.textLabel.text = fontName; 54 cell.textLabel.font = [UIFont fontWithName:fontName size:[UIFont labelFontSize]]; 55 return cell; 56 } 57 58 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 59 return [_arrFamilyName objectAtIndex:section]; 60 } 61 62 @end
标签:
原文地址:http://www.cnblogs.com/huangjianwu/p/4576516.html