ios开发之在iOS应用中加载自定义字体显示
来源:互联网 发布:大连理工网络教育官网 编辑:程序博客网 时间:2024/05/17 21:05
在此以UITableView列表来展示iPhone支持的所有字体类型。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//字体家族总数
return [[UIFont familyNames] count]; }- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//字体家族包括的字体库总数 return [[UIFont fontNamesForFamilyName:[[UIFont familyNames] objectAtIndex:section] ] count];}- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ //字体家族名称 return [[UIFont familyNames] objectAtIndex:section];}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:index] atScrollPosition:UITableViewScrollPositionMiddle animated:NO]; return index;}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; }
// Configure the cell. cell.textLabel.textColor = indexPath.row %2 ? [UIColor orangeColor] : [UIColor magentaColor];
//字体家族名称 NSString *familyName= [[UIFont familyNames] objectAtIndex:indexPath.section];
//字体家族中的字体库名称 NSString *fontName = [[UIFont fontNamesForFamilyName:[[UIFont familyNames] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont fontWithName:fontName size:14.0f]; //查找微软雅黑字体 if([fontName isEqualToString:@"MicrosoftYaHei"]) { NSLog(@"微软雅黑"); } cell.textLabel.text = [NSString stringWithFormat:@"%@ - %@", familyName, fontName ]; return cell;
}
但问题是,设计师在设计UI效果图时经常会使用其他的字体,怎么样才能使我们的应用支持这些字体显示了?
解决方法其实也很简单, 你自需如下几步就可以实现自定义的字体显示了。(在此以常用的 微软雅黑 字体 为例)
1. 找到你需要的字体库.ttf文件,导入到项目工程中
2. 在Info.plist文件中,加入自定义字体库支持的说明
3. 在系统提供的UIFont类中,查找到你需要的字体库再设置到需要显示的控件上即可。
现在在列表中已经能看到我们自定义的字体库 微软雅黑 (MicrosoftYaHei)。 在列表中显示的效果图如下所示:
就这么简单!
- ios开发之在iOS应用中加载自定义字体显示
- 在iOS开发中使用自定义字体
- 在iOS开发中使用自定义字体
- 在iOS开发中使用自定义字体
- iOS开发中自定义字体
- 如何在iOS应用中使用自定义字体
- IOS 加载自定义字体
- iOS开发之-自定义设置字体
- iOS开发之添加自定义字体
- ios开发中使用自定义字体
- iOS开发中怎么自定义字体?
- iOS开发中如何自定义字体?
- ios开发 添加自定义字体
- ios开发 添加自定义字体
- iOS开发 - 使用自定义字体
- iOS开发使用自定义字体
- 如何把自定义的字体添加到 iOS 应用中?
- iOS开发之如何在Xcode中显示断点堆栈
- 修改进度条ProgressBar颜色
- JS的正则表达式
- Apache2.2启动时报错:The requested operation has failed!
- OpenGL 三维纹理
- Linux下字符集的安装
- ios开发之在iOS应用中加载自定义字体显示
- ruby学习之,数据 表达式 控制
- ubuntu 学习二(RPM)
- xheditor
- 感悟
- php5.2与5.3性能测试对比
- Boost 的事件管理架構:Signal / Slot(上)
- classpath 和 classpath* 区别以及如何覆盖在配置文件中的Bean ID
- android程序安全的建议