ios - 如何使用系统字体调整操作表元素字体的大小?

标签 ios objective-c uiactionsheet

enter image description here

基本上我想创建一个带有 web View 的富文本格式编辑器。

我已经使用下面的代码检索了我设备中所有字体的名称。我现在想在我的 Web View 中选择一些文本并在其上应用该字体,因此我选择一个操作表来显示所有名称并在其上设置字体。我的问题是有些字体名称太大,并且都设置为相同的字体样式。我想将字体名称显示为字体实际样式。

// array
NSMutableArray *fontNames = [[NSMutableArray alloc] init];

// get font family
NSArray *fontFamilyNames = [UIFont familyNames];

// loop
for (NSString *familyName in fontFamilyNames)
{
    NSLog(@"Font Family Name = %@", familyName);

    // font names under family
    NSArray *names = [UIFont fontNamesForFamilyName:familyName];

    NSLog(@"INSIDE LOOP Font Names = %@", fontNames);

    // add to array
    [fontNames addObjectsFromArray:names];
}
NSLog(@"OUT OF LOOP Font Names = %@", fontNames);

// [fontNames release];

下面是我如何在我的 webview 选定文本上应用选择字体:

NSString *selectedButtonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
selectedButtonTitle = [selectedButtonTitle lowercaseString];

if ([actionSheet.title isEqualToString:@"Select a font"])
{        
    [printContentWebView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.execCommand('fontName', false, '%@')", selectedButtonTitle]];
}

我希望在我的操作表中有这样的输出

enter image description here

最佳答案

你的问题出在你的 UITableView 上,因为你没有发布 UIActionSheetUITableView 的代码,我创建了一个项目并将其上传到 Github ( link ),您可以找到我如何使用以下属性设法调整行文本的大小:

cell.textLabel.adjustsFontSizeToFitWidth = YES;

关于ios - 如何使用系统字体调整操作表元素字体的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17526488/

相关文章:

iOS 应用程序在后台执行任务

ios - 创建自定义 UITableViewCell 时崩溃

objective-c - 什么是代表?

ios - UICollectionView dequeueReusableCellWithReuseIdentifier 导致性能问题

uitabbarcontroller - 使用 Storyboards Get TabBar Reference for UIActionSheet showFromTabBar

iOS 7 UIActionSheet 透明

ios - 带有图像的 UIActionSheet

iphone - iOS动态改变UINavigationBar的背景图片

ios - 当我在搜索栏上单击取消时,如何重新加载 tableview 中的所有数据?(IOS/Swift)

objective-c - 如何使主窗口在 Cocoa 中可见?