zoukankan      html  css  js  c++  java
  • 044设置屏幕中显示不同字体的文本

    效果如下:

    ViewController.h

    1 #import <UIKit/UIKit.h>
    2 
    3 @interface ViewController : UITableViewController
    4 @property (strong, nonatomic) NSMutableDictionary *mDicFontName;
    5 @property (copy, 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
  • 相关阅读:
    JMeter学习-图形化 HTML 报表概要说明
    转《Python爬虫学习系列教程》学习笔记
    PYTHON __main__
    python property
    loadrunner脚本,如何获取lr的变量以及lr变量和其他程序语言的变量的转换
    参考链接
    彻底抛弃脚本录制,LR脚本之使用web_custom_request函数自定义http请求
    如何看Analysis分析图
    Ubuntu16.04安装QQ2015
    Ubuntu16.04运行LSD-SLAM踩坑笔记
  • 原文地址:https://www.cnblogs.com/huangjianwu/p/4576516.html
Copyright © 2011-2022 走看看