Thursday, January 27, 2011

add custom font on iphone

https://github.com/zynga/FontLabel

Sunday, January 23, 2011

add button to UItableview cell

myButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton1.frame = CGRectMake(0, 20, 80, 30); // position in the parent view and set the size of the button
[myButton1 setTitle:@"MAIL!" forState:UIControlStateNormal];
// add targets and actions

[myButton1 addTarget:self action:@selector(buttonClicked1:) forControlEvents:UIControlEventTouchUpInside];
// add to a view
//[self addSubview:myButton];
myButton1.tag=jk;//indexPath.row;
//[self.view addSubview:myButton];
[cell.contentView addSubview:myButton1];



/// ADDING METHOD TO THOS BUTTONS





- (IBAction)buttonWasPressed:(id)sender
{
NSIndexPath *indexPath =
[self.myTableView
indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
NSUInteger row = indexPath.row;

// Do something with row index
}

Tuesday, January 18, 2011

color UI title sectionview

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 44.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// create the parent view that will hold header Label
UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 150.0, 44.0)]autorelease];






NSString *sectionName = nil;

switch(section)
{
case 0:

if(counter<=3)
NSLog(@"ok");

// create the buNSLog(@"ok");tton object
UILabel * headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero]autorelease] ;
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor whiteColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont boldSystemFontOfSize:20];
headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 44.0);

// If you want to align the header text as centered
// headerLabel.frame = CGRectMake(150.0, 0.0, 300.0, 44.0);

headerLabel.text = @"Description"; // i.e. array element
[customView addSubview:headerLabel];


if(counter==7)

headerLabel.text = @""; // i.e. array element
[customView addSubview:headerLabel];

//sectionName = @"DES-";

break;

case 1:

Sunday, January 16, 2011

Avoid shuffling of data in UITABLE Section view

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *CellIdentifier=nil ;


NSMutableArray *Array= [[[NSMutableArray alloc] initWithObjects: @"One",@"Two", @"Three",@"Ad",@"Ae",@"Ah",@"Aj" ,nil]autorelease];



CellIdentifier = [Array objectAtIndex:indexPath.section];




///302-1021-9244-4658-1994-3384

UITableViewCell * cell = [tabelView dequeueReusableCellWithIdentifier:CellIdentifier];

//number++;
// NSLog(@" NUMBER IS %d",number);
// if (cell != nil)
//if(number==1);
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
// // Set up the cell








appDelegate = (DatabaseTestAppDelegate *)[[UIApplication sharedApplication] delegate];
switch(indexPath.section)
{
}


}

Thursday, January 6, 2011

Load webview inside Table view

CGRect bounds = CGRectMake(10, 90, 320, 180);//[[UIScreen mainScreen] applicationFrame];
UIWebView *localwebView = [[UIWebView alloc] initWithFrame: bounds ];
[self.view addSubview:localwebView];

NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];

localwebView.scalesPageToFit = YES;
[localwebView loadRequest:request];

Friday, December 17, 2010

to check app running first time or not on iphone

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (![prefs objectForKey:@"alert"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"this is 1st time" message:@"Some description"
delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"alert"];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@" this is 2nd time!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release];
NSLog(@" DEJA VU");

}

[[NSUserDefaults standardUserDefaults] synchronize];

Wednesday, October 20, 2010

IPhone GPS

- (CLLocationManager *)locationManager {
NSLog(@"lattttttttiiiiiiiiiiiiiudeeeeeeeee");
if (locationManager != nil) {
return locationManager;
}

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;


return locationManager;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {





//[locationMeasurements addObject:newLocation];


NSLog(@"l89899898ee");

#pragma mark lat


NSString *lat = [[NSString alloc] initWithFormat:@"%0.3f", newLocation.coordinate.latitude];



// NSLog(@"1l89899898ee");

NSString *lonn = [[NSString alloc] initWithFormat:@"%0.3f", newLocation.coordinate.longitude];



//latitudeString =newLocation.coordinate.latitude;
//latitudeString=lat;
//NSLog(@"lat is %@", lat);
//self.myLatitude = latitudeString;
//[latitudeString release];
#pragma mark long

//NSLog(@"2l89899898ee");

NSUserDefaults *alat = [NSUserDefaults standardUserDefaults];
[alat setObject:lat forKey:@"Latitude"];
//NSLog(@"%@",latitudeString);


//NSLog(@"3l89899898ee");
NSUserDefaults *along = [NSUserDefaults standardUserDefaults];
[along setObject:lonn forKey:@"Longitude"];

//NSLog(@"lon fgfgfgfg is %@", lonn);
//longitudeString=newLocation.coordinate.longitude;
//longitudeString=lon;

//NSLog(@"4l89899898ee");



}

- (void)locationManager: (CLLocationManager *)manager didFailWithError: (NSError *)error
{
NSLog(@"Location Error: %@",error);
switch([error code])
{
case kCLErrorNetwork: // general, network-related error
{
NSLog(@"please check your network connection or that you are not in airplane mode");
}
break;
case kCLErrorDenied:{
NSLog(@"user has denied to use current Location");
}
break;
default:
{
NSLog(@"unknown network error");
}
break;
}
[manager stopUpdatingLocation];
}



- (void)starte {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];



NSLog(@" thread stretr ");
[[self locationManager] startUpdatingLocation];


NSLog(@" main tgreas point is %@",latitudeString);







NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];

// getting an NSString
NSString *Latu = [prefs stringForKey:@"Latitude"];
NSLog(@" new lati is %@",Latu);





NSUserDefaults *alongs = [NSUserDefaults standardUserDefaults];
NSString *Longu = [alongs stringForKey:@"Longitude"];

NSLog(@" new longu is %@",Longu);


#pragma mark APP iD

#pragma mark sysID
NSString *sysID=[[UIDevice currentDevice] uniqueIdentifier];
NSLog(@" ID IS %@",sysID);

NSString *ip=@"ip";
NSString* OS=@"3";

//NSLog(@"latitude is %@", myString );
//latitudeString=@"1.3";
//longitudeString=@"103.8";

NSString *AppID=[NSString stringWithFormat:@"%@|%@|%@|%@|%@",Latu,Longu,sysID,ip,OS];
NSLog(@" MY APPLE OD IS %@",AppID );


NSUserDefaults *aDD = [NSUserDefaults standardUserDefaults];
[aDD setObject:AppID forKey:@"AppID"];

///////////////////////////////////////////////////////////////////////

[pool drain];
[pool release];



}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[[self locationManager] startUpdatingLocation];
[self performSelectorInBackground:@selector(starte) withObject:nil];
}

Monday, October 18, 2010

Flip navigation controller

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:YES];
[self.navigationController pushViewController:atab animated:YES];
//[self.navigationController pushViewController:myViewController animated:NO];
[UIView commitAnimations];

Friday, October 15, 2010

change navigation bar to black

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

Thursday, October 14, 2010

remove charcater from string

lets say you have @"hello" now ir order to get ello you can do this
NSString *newStr = [myString substringWithRange:NSMakeRange(1, [myString length] - 1)];

FEEDJIT Live