iphone apps font change doesn't look like it should - iphone

I've read here how to code the font exchange, I have two following questions,
1)why the actual font looks different from what it should look like
2)do i have to first install the fonts on my machine?

If you are using system fonts then its ok.
But to use custom fonts which are not provided by xcode then refer this
How to include and use new fonts in iPhone SDK?
EDIT:
To check fonts are added properly or not call this function and check names of fonts properly
-(void)checkFontList
{
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger family, font;
for (family=0; family<[familyNames count]; ++family)
{
NSLog(#"Family name: %#", [familyNames objectAtIndex:family]);
fontNames = [[NSArray alloc] initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:family]]];
for (font=0; font<[fontNames count]; ++font)
{
NSLog(#" Font name: %#", [fontNames objectAtIndex:font]);
}
[fontNames release];
}
[familyNames release];
}

Related

Objective-c Array Learning

Okay I am learning about arrays and how to work with them like I used to...... (Used to do alot of scripting but now am trying to learn to develop ipad and iphone app's
But my issue is I have it where it pulls a bunch of data from yahoo finance with a for loop..
But now my issue is how can I work with just one peice of the array data that has been pulled
here is my example
-(IBAction) clicked:(id)sender {
NSString * StockOneYahooFinance = [NSString stringWithFormat:#"http://finance.yahoo.com/q/hp?s=S+Historical+Prices"];
NSString * PulledStockOne = [NSString stringWithContentsOfURL:[NSURL URLWithString:StockOneYahooFinance] encoding:1 error:nil];
for (i=1;i<=10;i++){
NSString *StartPulling = [[PulledStockOne componentsSeparatedByString:#"nowrap align="] objectAtIndex:i];
NSString *StartOpen = [[StartPulling componentsSeparatedByString:#">"] objectAtIndex:3];
NSString *Open = [[StartOpen componentsSeparatedByString:#"<"] objectAtIndex:0];
NSString *StartClose = [[StartPulling componentsSeparatedByString:#">"] objectAtIndex:9];
NSString *Close = [[StartClose componentsSeparatedByString:#"<"] objectAtIndex:0];
NSMutableArray *StockOpens = [[NSMutableArray alloc] initWithCapacity:6];
[StockOpens addObject:Open];
sixtyday.text = [OpenValues objectAtIndex:10];
nintyday.text = [CloseValues objectAtIndex:10];
if ([OpenValues objectAtIndex:10]=[OpenValues objectAtIndex:11] {
sevenday.text = #"Plus One";
}
}
}
But now I want to do something like
year.text=StockOpens[5];
How can I do this.
Starting in Xcode 4.4 (LLVM 4.0), literals can be used for C-style subscripting in Objective-C.
year.text = StockOpens[5];
LLVM has documented the use of literal here: Objective-C Literals
Note: Because Clang will translate the literal usage, in this case to objectAtIndexedSubscript:, the OS X v10.8 (or iOS 6) Foundation framework is required.
StockOpens is an array object so you need to call a method to get the object at an index. On NSMutableArray its [StockOpens ObjectAtIndex:5]
year.text = [[StockOpens objectAtIndex:5]StringValue];
To do StockOpens[5] you need to use a C-array.
This depends on what kind/class of objects you fill StockOpens with, if it's simply NSStrings, you can do
year.text = [StockOpens objectAtIndex:5];
If it's some other object that is not a string, you can maybe call its description:
year.text = [[StockOpens objectAtIndex:5] description];
P. s.: there's documentation on developer.apple.com, please read it! This question is so simple (and fundamental) that it must not be asked on SO.

Multi Language Support in iphone application

I want to develop an iphone application where u can change the language from the application itself rather than iphone settings.
How can it be possible??
Is there any tutorial available for it??
Waiting for the responses.
Regards,
Jagruti
+(void)GetLangKey:(NSString *)Langkey
{
NSString *tmpstr=[NSString stringWithFormat:#"%#",[[NSBundle mainBundle]pathForResource:#"LanguageResources" ofType:#"bundle"]];
tmpstr =[tmpstr stringByAppendingString:#"/"];
tmpstr=[tmpstr stringByAppendingString:Langkey];
tmpstr =[tmpstr stringByAppendingString:#".lproj"];
// NSLog(#"%#",tmpstr);
myLocalizedBundle=[NSBundle bundleWithPath:tmpstr];
}
+(UIImage*)GetLocalImage:(NSString *)ImgName
{
NSString *filepath= [myLocalizedBundle pathForResource:ImgName ofType:#"png"];
UIImage *returnImg=[UIImage imageWithContentsOfFile:filepath];
return returnImg;
}
+(UIImage*)GetLocalImage:(NSString *)ImgName Type:(NSString *)imgType
{
NSString *filepath= [myLocalizedBundle pathForResource:ImgName ofType:imgType];
UIImage *returnImg=[UIImage imageWithContentsOfFile:filepath];
return returnImg;
}
+(NSString *)getLocalvalue:(NSString*)Key
{
NSString *localValue=NSLocalizedStringFromTableInBundle(Key,#"Localized",myLocalizedBundle,#"");
//NSLog(#"%#",localValue);
return localValue;
}
when you changed Language change kay
[YourAppDelegate GetLangKey:(btn_Language.selected)?#"sp":#"en"];
Create Two Bundles As Strings Files Names Sp.lproj AND en.lproj
Give Same Key For Both Strings
Get Value Like Below
[YourAppDelegate getLocalvalue:#"Settings"];

TouchXML problem

I have got following xml which I need to parse using TouchXML.
<?xml version="1.0"?>
<categories>
<category0>
<title>Alcoholic Drinks</title>
<description>Buy beers, wines, sprits and champagne from the top online alocholic drink stores.
Whatever your tipple you are sure to find a drinks supplier from our top shops below:
</description>
<status>1</status>
<popularStatus></popularStatus>
<order></order>
<link>alcoholic-drinks</link>
<id>1</id>
</category0>
<category1>
<title>Art and Collectibles</title>
<description>Are you looking to buy contemporary or fine art, or do you prefer to make your own artwork?&#
Whether type of artwork or craft materials you are looking for, you are certain to find one of the shops below more than helpful:
</description>
<status>1</status>
<popularStatus></popularStatus>
<order></order>
<link>art-and-collectibles</link>
<id>2</id>
</category1>
<category2>
<title>Auctions</title>
<description>Are you looking for the UK's biggest and best Auction Sites?
The team at safebuyer.co.uk have scoured the web to find the UK's favourite auctions, so why wait, start your bidding now!
</description>
...
...
...
I am thinking to create two loops from root node in order to fetch title and link but coudnt figure out how to do it. Can anybody help please.
If you can change your XML file and make all the category tag same. You can put all ... Instead of ... and ....
So that would be pretty easy to parse. You just need to make category class and all the tag would be parse automatically if you have correct xml parsing code.
CXMLNode *node;
for(i=0; i<10 ; i++){
NSString *xpath = [NSString stringWithFormat:#"//category%d/title", i];
NSArray *title = [[node nodesForXPath:xpath] stringValue];
}
Use the above code..
CXMLElement *element;
NSArray *titleItems = [[NSArray alloc] initWithArray:[element nodesForXPath:#"//category" error:nil]];
for(CXMLElement *item in titleItems){
NSString *title = [[item selectSingleNode:#"title"] stringValue];
}
Note: category node should be repeating.....
The code below gives you a dictionary where keys are titles and data are the links. Of course, if your XML document is "big", this is not the best way to do it.
CXMLDocument *doc = [[[CXMLDocument alloc] initWithXMLString:theXML options:0 error:nil] autorelease];
NSArray *categories = nil;
NSMutableDictionary* results = nil;
categories = [doc nodesForXPath:#"/categories/*[starts-with(name(), 'category')]" error:nil];
if (categories != nil && [categories count] > 0)
{
results = [NSMutableDictionary dictionaryWithCapacity:[categories count]];
for (CXMLElement *category in categories)
{
NSArray* titles = [category elementsForName:#"title"];
if ([titles count] >0)
{
NSArray* links = [category elementsForName:#"link"];
[result setObject:([links count]>0?[[links objectAtIndex:0] stringValue]:nil;
forKey:[[titles objectAtIndex:0] stringValue]];
}
}
}

help on sorting NSMutableDictionary strings that are URL images

i want to populate the tablecell with title and imageurl from xml list.
i manage to store the title (NSMutableDictonary *sections )and imageURL (NSMutableDictonary *sectionsImg) into 2 NSMutableDictionary respectively.
/*******This is in viewDidLoad***/
Directory *allDirectory = [appDelegate.directories objectAtIndex:0];
for (allDirectory in appDelegate.directories)
{
NSDictionary *dica = [NSDictionary dictionaryWithObject:allDirectory.dirTitle forKey:#"dirTitle"];
NSDictionary *dico = [NSDictionary dictionaryWithObject:allDirectory.imageURL forKey:#"imageURL"];
[dirName addObject:dica];
[dirImage addObject:dico];
//NSLog(#"dic of items : %#",dirImage);
}
for (allDirectory in appDelegate.directories)
{
//retrieve the first letter from every directory title (dirTitle)
NSString * c = [allDirectory.dirTitle substringToIndex:3];
NSString * m = allDirectory.imageURL;
found = NO;
find = NO;
for (NSString *str in [self.sections allKeys])
{
if ([str isEqualToString:c])
{
found = YES;
}
}
for (NSString *stra in [self.sectionsImg allKeys])
{
if([stra isEqualToString:m])
{
find = YES;
}
}
if (!found)
{
[self.sections setValue:[[NSMutableArray alloc]init] forKey:c ];
[self.sectionsImg setValue:[[NSMutableArray alloc]init] forKey:m];
}
if (!find)
{
[self.sectionsImg setValue:[[NSMutableArray alloc]init] forKey:m];
}
}
for (NSDictionary *directory in dirName)
{
[[self.sections objectForKey:[[directory objectForKey:#"dirTitle"] substringToIndex:3]] addObject:directory];
//NSLog(#"hehehe have : %#",sections);
}
for (NSDictionary *directoryImg in dirImage)
{
//[[self.sectionsImg objectForKey:[[directoryImg objectForKey:#"imageURL"] substringFromIndex:0]] addObject:directoryImg];
[[self.sectionsImg objectForKey:[directoryImg objectForKey:#"imageURL"]] addObject:directoryImg];
//NSLog(#"HOHOHO have : %#",sectionsImg);
}
And on cellForRowAtIndexPath i declare a dictionary
NSDictionary *dictionary = [[self.sections valueForKey:[[[self.sections allKeys] sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
cell.textLabel.text = [dictionary objectForKey:#"dirTitle"];
but when i tried to declare a dictionary for imageURL
NSDictionary *dictionaryImg = [[self.sectionsImg valueForKey:[[[self.sectionsImg allKeys] sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)] objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
it gives me a error :
Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
any idea why? the logic is supposed to be the same where xml title and url can be retrieve and be displayed. Title is retrievable but imageURL is not. Help is deeply appreciated !
You are trying to sort an array... except for the fact your array isn't an array, but a NSDictionary.
Your code isn't the best at the moment. Your getting the idea of Dictionaries wrong and may be confusing them with arrays, so my best guess is your quite new to programming into objective-c.
You have two lists of things, if I'm not mistaken. The first list is the list of names, and the second list is an image corresponding with that name.
Below I'm going to do two things:
Firstly, I'm giving you two ways on how to fix your problem. It has a sample code included and gives you a small explanation with it. The possibility exist you don't understand parts of what I describe. In that case, you should;
Check out the link I described below the two solutions. It has a tutorial which makes you understand everything about arrays, dictionaries, tables and, as a bonus, XML-parsing.
So, in my opinion, you can do two things:
The first one is using an array of NSDictionaries. You'd be using a code which looks like:
NSMutableDictionary *itemOne = [[NSMutableDictionary alloc] init];
NSMutableDictionary *itemTwo = [[NSMutableDictionary alloc] init];
NSMutableArray *listOfAll = [[NSmutableArray alloc] init];
NSString *itemOneName = [[NSString alloc] initWithFormat:#"This is picture 1"];
NSString *itemTwoName = [[NSString alloc] initWithFormat:#"This is picture 2"];
NSData *imageOneData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: #"http://myurl/mypic1.jpg"]];
NSData *imageTwoData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: #"http://myurl/mypic2.jpg"]];
UIImage *itemOneImage = [UIImage imageWithData: imageOneData];
UIImage *itemTwoImage = [UIImage imageWithData: imageTwoData];
[itemOne setObject:itemOneNameString forKey:#"Name"];
[itemOne setObject:itemOneImage forKey:#"Image"];
[itemTwo setObject:itemTwoNameString forKey:#"Name"];
[itemTwo setObject:itemTwoImage forKey:#"Image"];
[listOfAll addObject:itemOne];
[listOfAll addObject:itemTwo];
Anything can be filled using that array. Just use something with a for-loop to iterate through your array.
for (int i = 0; i < [listOfAll count]; i++)
{
NSMutableDictionary *currentItem = [[NSMutableDictionary alloc] initWithDictionary:[listOfAll objectAtIndex:i]];
//Do something with that current item
}
You can also use that index in your tableView. In that case, you have to use your variable section instead of i to get your desired index.
The second one is using two arrays. Imagine you get an image named imageOne with the text imageName. Then you should use:
NSMutableArray *nameList = [[NSMutableArray alloc] init];
[nameList addObject: imageName];
NSMutableArray *imageList = [[NSMutableArray alloc] init];
[imageList addObject: imageOne];
If you want to use a certain item out of those lists, you just have to use the same indexnumber.
For example:
[theTitleLabel setText:[[NSString alloc] initWithFormat:#"%#", [nameList objectAtIndex:x]]];
[theImageView setImage:[imageList objectAtIndex:x]];
Make sure the x's are the same number.
I understand this is all a lot of information, especially if you're new to Objective - C. A tutorial exists which gives you a lot of information about how to use arrays, dictionaries and table views. As a bonus, you get to know a little about XML-parsing.
I suggest you walk through that tutorial and do everything and read everything it says. This should give you a nice start into the world of programming in iPhones.
Good luck!

NSFileManager, file extension

I am creating an iPhone application which makes a iphone act as a pendrive for easy file sharing.
In the first stage, i have some files(png, pdf, jpg, zip) in a directory and i made them display in the tableview in the form of mutable array. It displays in the tableView as shown below,
.DS_Store
.localized
gazelle.pdf
Hamburger_sandwich.jpg
IITD TAJ Picture 028_jpg.jpg
iya_logo_final_b&w.jpg
manifesto09-eng.pdf
RSSReader.sql
SimpleURLConnections.zip
SQLTutorial
I just want to display the name of the files and i do not want to display the extensions. I know that it is possible to extract the extensions of a file in NSFileManager. But i do not know how. Please help me to make my table view look like this
.DS_Store
.localized
gazelle
Hamburger_sandwich
IITD TAJ Picture 028_jpg
iya_logo_final_b&w
manifesto09-eng
RSSReader
SimpleURLConnections
SQLTutorial
Look into NSString's documentation, there you'll find stringByDeletingPathExtension.
The basic idea is that you do not want to update objects in existing array, but create a new array with filenames without extension, and throw the original array away.
This is how it can be done:
NSArray *stuff = [NSArray arrayWithObjects:#"image1.jpg", #"image2.png", #"image3.tiff", nil];
NSLog(#"input %#", stuff);
stuff = [stuff valueForKey:#"stringByDeletingPathExtension"];
NSLog(#"output %#", stuff);
I do not expect you to understand that code, therefore here's a more straightforward version:
NSArray *stuff = [NSArray arrayWithObjects:#"image1.jpg", #"image2.png", #"image3.tiff", nil];
NSLog(#"input %#", stuff);
NSMutableArray *output = [NSMutableArray array];
for (NSString *filename in stuff) {
NSString *filenameWithoutExtension = [filename stringByDeletingPathExtension];
[output addObject:filenameWithoutExtension];
}
NSLog(#"output %#", output);