Friday 28 October 2011

Formatting of titleforHeaderInSection


- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section {
 UILabel *sectionHeader = [[[UILabel alloc] initWithFrame:CGRectNull] autorelease];
 sectionHeader.backgroundColor = [UIColor clearColor];
 sectionHeader.textAlignment = UITextAlignmentLeft;
 sectionHeader.font = [UIFont boldSystemFontOfSize:10];
 sectionHeader.textColor = [UIColor whiteColor];
 sectionHeader.text = [[plistArray objectAtIndex:section]objectForKey:@"Header"]; // <-- allows loading of sectionHeader text from a plist
 return sectionHeader;
}
- (CGFloat)tableView:(UITableView *)tableViewheightForHeaderInSection:(NSInteger)section {
 return 40;
} 

Thursday 27 October 2011

How to set the zoomlevel of MKMapView


    MKCoordinateRegion region;
    region.center=newLocation.coordinate;   // location
    MKCoordinateSpan span;
    span.latitudeDelta=120;               //  0.001 to 120
    span.longitudeDelta=120;
    region.span=span;
    [self.mapView setRegion:region animated:YES];   

Tuesday 4 October 2011

Add Custom delegate in iPhone

You will want to declare a delegate protocol for your class. An example of a delegate protocol and interface for class Foo might look like this:
 
 
@class Foo;
@protocol FooDelegate <NSObject>
@optional
- (BOOL)foo:(Foo *)foo willDoSomethingAnimated:(BOOL)flag;
- (void)foo:(Foo *)foo didDoSomethingAnimated:(BOOL)flag;
@end
@interface Foo : NSObject {
     NSString *bar;
     id <FooDelegate> delegate;
}
@property (nonatomic, retain) NSString *bar;
@property (nonatomic, assign) id <FooDelegate> delegate;
- (void)someAction;
@end
 
 
 
Don't forget to synthesize your properties in the @implementation.
 
 
How to USE: 
 
@interface SomeClass : SuperClass <FooDelegate> {} 
 
 
Foo *obj = [[Foo alloc] init];
[obj setDelegate:self];
 
 
 
Reference: 
http://stackoverflow.com/questions/645449/how-to-use-custom-delegates-in-objective-c 

Monday 3 October 2011

Gif Animations in iPhone


http://www.bigoo.ws/Images/flowers-gif/14-1-1109.htm


  UIImageView *imgView;
 @property (nonatomic, retain) IBOutlet UIImageView *imgView;
 @synthesize imgView;

  imgView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"1.png"],[UIImage imageNamed:@"2.png"],[UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"4.png"],nil];
    imgView.animationDuration = 3.5;
    imgView.animationRepeatCount = 0;
    [imgView startAnimating];