Thursday, April 26, 2012

Custom font in IPhone Application

Sometimes we have apply our own custom fonts in application.
Normally we add the fontfile name with extension to resources and a entry in plist.
In code we will use the font some thing like this

[lblTest setFont: [UIFont fontWithName: @"fontfilenamewithoutextension" size:30]];

But this doesn't works if font name is different from font file name.
To get the font name use below code.

   NSArray *familyNames = [UIFont familyNames];
    for( NSString *familyName in familyNames ){
        printf( "Family: %s \n", [familyName UTF8String] );
        NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
        for( NSString *fontName in fontNames ){
            printf( "\tFont: %s \n", [fontName UTF8String] );
        }
    }

Pick the font name from the list which is printed in the log and then just replace that 
[lblTest setFont: [UIFont fontWithName@"fontname" size:30]];


Now your custom font works :).

Thursday, April 19, 2012

Disabling native iOS vertical window movement in phonegapp application

When we are developing phonegap application page moves up and down when we scroll in the webview eventhough page has little data.
- (void)webViewDidFinishLoad:(UIWebView *)theWebView 
    { 
              for(id subview in theWebView.subviews) { 
              if([[subview class]isSubclassOfClass:[UIScrollView class]]) 
              ((UIScrollView *)subview).bounces = NO; 

    } 
Just add above extra code in appdelegates.m file webviewdidfinish load function.


This will fix the issue.