Search code examples
iosobjective-cuiactionsheet

How to Resize action Sheet element font with system font?


enter image description here

Basically I want to create a Rich Text Format editor with web view.

I have retrieved all the names of the fonts in my device using the code below. I now want to select some text in my web view and apply that font on it, so I choose a Action Sheet to display all names and set the font on it. My problem is some font names are too big and all are set with same font style. I want to display the font name as the font actual style.

// 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];

And here is how I'm applying selection font on my webview selected text:

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

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

And I want such output in my actionsheet

enter image description here


Solution

  • your problem is in your UITableView, since you didn't post the code of the UIActionSheet and UITableView code, I've created a project and uploaded it to a Github (link), you can find how i can manage to resize the text of the rows using the following property:

    cell.textLabel.adjustsFontSizeToFitWidth = YES;