Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-17-2011, 11:39 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 1
indiaxxo is on a distinguished road
Default UIPickerView on a Popupcontroller

Hi guys, I'm a newbie to programming and in my project work I have these requirements.
1. I have to load System fonts onto a UIPickerView(in the component 1).
2. In the same way in the other PickerView component I have to give Font size.

How do I load the system fonts into an array(I couldn't load them onto NSMutableArray), Kindly help me with my project.

Thanks in advance.
indiaxxo is offline   Reply With Quote
Old 11-18-2011, 12:17 AM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

You'll have to create a plist of all the font names. The names can be found here: iOS Fonts.

Then what I would do is create a category on UIFont and add a method called knownFontNames or systemFontNames. Have it create an array from the plist and return it.

Then, I'd create a view controller named FontPickerController or something like that. In that controller, retrieve the font names array and use it to populate 1 UIPickerView. Then, create a loop and add NSNumber objects. Something like this:
Code:
int i = 1;
int maxFontSize = 72;
NSMutableArray *fontSizes = [[NSMutableArray alloc] initWithCapacity:maxFontSize];
for (i = 1; i < maxFontSize; i++) {
NSNumber *fontSize = [NSNumber numberWithInt:i];
[fontSizes addObject:fontSize];
}
Then use that array to populate the second UIPickerView. You'll have convert the NSNumber objects to string first though which isn't that hard:
Code:
NSString *numberString = [NSString stringWithFormat:@"%i", [aNSNumberObject intValue]];
The %i is a format code, in this case it's the format code for an integer. With format codes, you can create dynamic strings.

I'm guessing you want to use these fonts in some way, so I'd go with delegation so that you can reuse this font picker in the future. Explaining how to setup a delegate is going to be a little bit too long for this post but there are a bunch of tutorials online. And you'd probably want to use the delegate for other things like specifying the max font size so you don't have to modify your font picker if you want to say change the max font size to 80 instead of 72.

Hope that helps.

Edit: And if you are only targeting iOS 5+, you should use a UIStepper control instead of a UIPickerView to have the user choose the font size.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.

Last edited by Domele; 11-18-2011 at 12:23 AM.
Domele is offline   Reply With Quote
Reply

Bookmarks

Tags
fonts for iphone, fontsize, pickerview, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 399
17 members and 382 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, chiataytuday, dre, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, QuantumDoja, Retouchable, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:25 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0