ios 字体样式展示,字体名字跟它的样式以展示在列表上

感受ios字体样式

上一篇简单介绍了获取ios支持的字体样式的方法,并且给出了最终的结果,但直观效果不是很好,不能很好的感受到各种字体的不同。相信通过本篇可以弥补此缺憾,本篇通过uitableview以列表的形式显示各种字体样式。

//

//  FontDemoViewController.h

//  FontDemo

//

//  Created by mac on 12-3-6.

//  Copyright 2012年 __wwssttt@163.com__. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface FontDemoViewController : UITableViewController

@property(nonatomic,retain)NSArray* fontFamilies;

@property(nonatomic,retain)NSMutableArray* fontNames;

@end

 

 

//

//  FontDemoViewController.m

//  FontDemo

//

//  Created by mac on 12-3-6.

//  Copyright 2012年 __wwssttt@163.com__. All rights reserved.

//

 

#import "FontDemoViewController.h"

 

@implementation FontDemoViewController

@synthesize fontFamilies,fontNames;

- (id)initWithStyle:(UITableViewStyle)style

{

    self = [superinitWithStyle:style];

    if (self) {

        // Custom initialization

    }

    returnself;

}

 

- (void)didReceiveMemoryWarning

{

    // Releases the view if it doesn't have a superview.

    [superdidReceiveMemoryWarning];

    

    // Release any cached data, images, etc that aren't in use.

}

 

#pragma mark - View lifecycle

 

- (void)viewDidLoad

{

    [superviewDidLoad];

 

    // Uncomment the following line to preserve selection between presentations.

    // self.clearsSelectionOnViewWillAppear = NO;

 

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.

    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    self.fontNames = [[NSMutableArrayalloc] init];

    self.fontFamilies = [UIFontfamilyNames];

    for (NSString* families inself.fontFamilies) {

        NSArray* tmp = [UIFontfontNamesForFamilyName:families];

        [self.fontNamesaddObject:tmp];

    }

}

- (void)viewDidUnload

{

    [superviewDidUnload];

    // Release any retained subviews of the main view.

    // e.g. self.myOutlet = nil;

    if (self.fontFamilies != nil) {

        [selfsetFontFamilies:nil];

    }

    

    if (self.fontNames != nil) {

        [selfsetFontNames:nil];

    }

}

- (void)viewWillAppear:(BOOL)animated

{

    [superviewWillAppear:animated];

}

- (void)viewDidAppear:(BOOL)animated

{

    [superviewDidAppear:animated];

}

- (void)viewWillDisappear:(BOOL)animated

{

    [superviewWillDisappear:animated];

}

 

- (void)viewDidDisappear:(BOOL)animated

{

    [superviewDidDisappear:animated];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    // Return YES for supported orientations

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

#pragma mark - Table view data source

 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

#warning Potentially incomplete method implementation.

    // Return the number of sections.

    return [self.fontFamiliescount];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

#warning Incomplete method implementation.

    // Return the number of rows in the section.

    NSLog(@"%d",[[self.fontNamesobjectAtIndex:section] count]);

    return [[self.fontNamesobjectAtIndex:section] count];

}

-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    return [self.fontFamiliesobjectAtIndex:section];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    staticNSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];

    }

    int section = indexPath.section;

    int row = indexPath.row;

    NSLog(@"%@",[[self.fontNamesobjectAtIndex:section] objectAtIndex:row]);

    cell.textLabel.text = [[self.fontNamesobjectAtIndex:section] objectAtIndex:row];

    [cell.textLabelsetFont:[UIFontfontWithName:[[self.fontNamesobjectAtIndex:section] objectAtIndex:row] size:20]];

    // Configure the cell...   

    return cell;

}

/*

// Override to support conditional editing of the table view.

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    // Return NO if you do not want the specified item to be editable.

    return YES;

}

*/

/*

// Override to support editing the table view.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (editingStyle == UITableViewCellEditingStyleDelete) {

        // Delete the row from the data source

        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

    }   

    else if (editingStyle == UITableViewCellEditingStyleInsert) {

        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view

    }   

}

*/

/*

// Override to support rearranging the table view.

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath

{

}

*/

/*

// Override to support conditional rearranging of the table view.

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    // Return NO if you do not want the item to be re-orderable.

    return YES;

}

*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // Navigation logic may go here. Create and push another view controller.

    /*

     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];

     // ...

     // Pass the selected object to the new view controller.

     [self.navigationController pushViewController:detailViewController animated:YES];

     [detailViewController release];

     */

}

@end

 

最终的结果如下:






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值