Pages

Subscribe:

Labels

Sep 14, 2010

UITextView with HTML

You must bother sometimes when you need to display a multi color text in your application! You must be using many uilabels with fissrent color. But you need not do this all. Here is a simple way to show your HTML file directly into UITextView.
What you need is to save all text into a html file and call that file in your UITextView with the help of this code bellow-

// Load the HTML source
self.sourceText = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"htmlfile" ofType:@"html"]];
[myTextView setContentToHTMLString:self.sourceText];

You may download the sample app from here

UITableView with Textfield Controls auto Moved Up on select

This example shows a signup page with UITextFields and UILabels. When a field is selected by a user then it doesn't get overlapped by the keypad, textfields automatically moves up on select and auto moves down on 'done' button click.
Remember, you can easily implement same concept using UITableViewController, but in that case there will not be more customization options like, static background image etc. So this example is based on UIViewController with UITableViewDelegate.
The method bellow works for moving up and down of whole TableView

- (void) moveToUpDownAnimation:(NSInteger) upOrDown:(NSInteger) yAxis {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
itemTableView.frame = CGRectMake(itemTableView.frame.origin.x, (itemTableView.frame.origin.y + yAxis), itemTableView.frame.size.width, 368);
heading.frame = CGRectMake(heading.frame.origin.x, (heading.frame.origin.y + yAxis), heading.frame.size.width, heading.frame.size.height);
[UIView commitAnimations];
}

You may download the sample app from here

Sep 10, 2010

UISwitch Sample with custom label and colors (Customized UISwitch)


This project will let you edit the Text of UISwitch that is default 'ON' and 'OFF' always.
Also you may edit the color of Text also.
Download sample code here.

Sep 6, 2010

UITables with Asynchronous Downloading of Images



Now you may easily implement the concept of Asynchronus Image loading on your iphone application.
We all know that when a table view has several images then first it has to download all the images from internet after then tabel view appears.
In this example LoadImageFromURL will return right away, the image will load in the background, and will automatically appear in the view when its finished downloading. Before the image is downloaded, it will show a default placeholder image and it can be set inside the code of 'AsyncImage.m' file-

    }else {
// Use a default placeholder when no cached image is found
UIImageView *imageView = [[[UIImageView alloc] initWithImage:[UIImage
  imageNamed:@"placeholder.png"]] autorelease];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:imageView];
imageView.frame = self.bounds;
[imageView setNeedsLayout];
[self setNeedsLayout];
}

And if you want to set a ActivityView during the image download, you may also set that-
    UIActivityIndicatorView *spinny = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    spinny.tag = SPINNY_TAG;
    spinny.center = self.center;
    [spinny startAnimating];
    [self addSubview:spinny];
    [spinny release];
Find an easygoing sample app here.

Dynamic UITabBarController and UINavigationController Autorotate


The sample bellow describes the creation of a application with dynamic UITabBarController that autorotates also with UITabBar, UINavigationBar.
For a easy implemetation of auto rotation follow the instructions bellow-

You must have declared UITabBarController into your delegate, right?
So now you need to over right that.

make a new class named- UITabBarController

code for UITabBarController.h-
#import <UIKit/UIKit.h>
@interface UITabBarController (rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@end


code for UITabBarController.m->
#import "UITabBarController.h"
@implementation UITabBarController (rotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
@end

Once these two files are added to your project, UITabBarController will be automatically overridden and the feature of auto rotation will work. Here you may download the sample code.


You may get Blog Post Alert on your cell phone via SMS. Subscribe to iphoneSampleCodes with your google account.

Indian users may subscribe via sms. Send ON iphonesamplecodes to 9870807070