iOS에서 시스템의 모든 글꼴을 가져와 표시
#import
@interface MyTableViewController : UITableViewController
@end
#import "MyTableViewController.h"
@interface MyTableViewController ()
@property (nonatomic, strong) NSArray *fontFamilyArray;
@property (nonatomic, strong) NSMutableArray *fontArray;
@end
@implementation MyTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
_fontFamilyArray = [UIFont familyNames];
_fontArray = [NSMutableArray array];
for (NSString* familyName in _fontFamilyArray) {
NSArray *fontArray = [UIFont fontNamesForFamilyName:familyName];
[_fontArray addObject:fontArray];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return _fontArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray* fontArr = [_fontArray objectAtIndex:section];
return fontArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 64;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger section = indexPath.section;
NSInteger row = indexPath.row;
NSString* fontName = [[_fontArray objectAtIndex:section] objectAtIndex:row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel.text = @" ABCDefgh";
cell.textLabel.font = [UIFont fontWithName:fontName size:15];
NSString* fontFamilyName = [_fontFamilyArray objectAtIndex:section];
fontFamilyName = [fontFamilyName stringByReplacingOccurrencesOfString:@" " withString:@""];
if ([fontFamilyName isEqualToString:@"Bodoni72Oldstyle"]) {
fontFamilyName = @"BodoniSvtyTwoOSITCTT";
}
NSString* fontDetail = [fontName stringByReplacingOccurrencesOfString:fontFamilyName withString:@""];
fontDetail = [fontDetail stringByReplacingOccurrencesOfString:@"-" withString:@""];
cell.detailTextLabel.text = fontDetail;
return cell;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return [_fontFamilyArray objectAtIndex:section];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger section = indexPath.section;
NSInteger row = indexPath.row;
NSString* fontName = [[_fontArray objectAtIndex:section] objectAtIndex:row];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@" " message:fontName preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@" " style:UIAlertActionStyleDefault handler:nil];
[alert addAction:okAction];
[self presentViewController:alert animated:YES completion:nil];
NSLog(@" :%@",fontName);
}
@end
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.