Translate

Thursday, August 22, 2013

Open Phone, SMS, Email, Map and browser apps in iPhone SDK



Here is how you can open default Phone app, SMS app, Email app, Maps app and browser app with openURL.
Open default Phone app in iPhone:
1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8004664411"]];
Open default SMS app in iPhone:
1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms://466453"]];
Open default Email app in iPhone:
1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://devprograms@apple.com"]];
Open default Maps app in iPhone:
1
2
3
4
5
6
7
8
9
10
11
NSString* addressText = @"1 Infinite Loop, Cupertino, CA 95014";
 
// URL encode the spaces
 
addressText =  [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
 
NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];
 
// lets throw this text on the log so we can view the url in the event we have an issue
 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
Open default Browser app in iPhone:
1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com/"]];

Tuesday, May 28, 2013

CustomCell

View Didload


objArray = [[NSMutableArray alloc] initWithObjects:
                [[ListObjects alloc] initWithName:@"Steak" andDesc:@"Rare"],
                [[ListObjects alloc] initWithName:@"Steak" andDesc:@"Medium"],
                [[ListObjects alloc] initWithName:@"Salad" andDesc:@"Caesar"],
                [[ListObjects alloc] initWithName:@"Salad" andDesc:@"Bean"],
                [[ListObjects alloc] initWithName:@"Fruit" andDesc:@"Apple"],
                [[ListObjects alloc] initWithName:@"Potato" andDesc:@"Baked"],
                [[ListObjects alloc] initWithName:@"Potato" andDesc:@"Mashed"],
                [[ListObjects alloc] initWithName:@"Bread" andDesc:@"White"],
                [[ListObjects alloc] initWithName:@"Bread" andDesc:@"Brown"],
                [[ListObjects alloc] initWithName:@"Hot Dog" andDesc:@"Beef"],
                [[ListObjects alloc] initWithName:@"Hot Dog" andDesc:@"Chicken"],
                [[ListObjects alloc] initWithName:@"Hot Dog" andDesc:@"Veggie"],
                [[ListObjects alloc] initWithName:@"Pizza" andDesc:@"Pepperonni"],
                nil ];

cellForRowAtIndexPath

    static NSString *CellIdentifier = @"Cell";
    ThumbCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    cell = [[ThumbCellView alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil imageName:objArray width:self.view.bounds.size.width];
    cell.backgroundColor=[UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;


ListObjects Class

-(id) initWithName:(NSString*)cateName andDesc:(NSString*)tltName
{
    self = [super init];
    if(self)
    {
        self.catName = cateName;
        self.titleName = tltName;
    }
    return self;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier imageName:(NSArray *)imageList width:(int)width
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
          int val;
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            if (width==320)
                val=0;
            else
                val=25;
        }
        else
        {
            if (width==768)
                val=0;
            else
                val=25;
        }
        
        for (int i=0;i<[imageList count];i++)
        {
            UIButton* cellBgImg;
            
            if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
            {
                cellBgImg = [[UIButton alloc] initWithFrame:CGRectMake(50+i*140+val, 10, 70, 90)];
            }
            else
            {
                cellBgImg = [[UIButton alloc] initWithFrame:CGRectMake(70+i*180+val, 65, 103, 133)];
            }
            
            UIImage *img=[UIImage imageNamed:@"image.png"];
            [cellBgImg setBackgroundImage:img forState:UIControlStateNormal];
        
[cellBgImg setTitle:[NSString stringWithFormat:@"%d",i+1] forState:UIControlStateNormal];
            cellBgImg.titleLabel.font=[UIFont fontWithName:@"Arial" size:0.0];
            
            cellBgImg.tag=i;
            
[cellBgImg addTarget:self action:@selector(btnpress:) forControlEvents:UIControlEventTouchUpInside];
cellBgImg.backgroundColor=[UIColor clearColor];
            [self addSubview:cellBgImg];
            
        }
    }
    return self;
}