1. "Download UIImage from HTTP server"

    Mon 11 May 2009

    //Download image from HTTP server

    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/intl/en_ALL/images/logo.gif"]];

    UIImage *image = [UIImage imageWithData:imageData];

    read more
  2. "Send file (images) to web server using POST method"

    Mon 11 May 2009

     

    //This example send email with attachment using server side

    //So iPhone will fill form and send proper request to web server using POST method

    //For test you can use attached sendEmail.php

     

    -(NSMutableData *)generateDataFromText:(NSString *)dataText fieldName:(NSString *)fieldName{

    NSString *post = [NSString stringWithFormat:@"--AaB03x\r\nContent-Disposition: form-data; name=\"%@\"\r\n ...

    read more
  3. "Rotate label (UILabel)"

    Mon 11 May 2009

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 50, 70)];

    label.numberOfLines = 2;

    label.text = @"text";

    label.backgroundColor = [UIColor clearColor];

    label.textColor = [UIColor whiteColor];

     

    label.highlightedTextColor = [UIColor blackColor];

    label.textAlignment = UITextAlignmentLeft;

    label.font = [UIFont systemFontOfSize:12];

     

    //rotate label in 45 degrees

    label.transform = CGAffineTransformMakeRotation( M_PI/4 );

     

    [self addSubview:label];

    [label ...

    read more
  4. "Add image to sqlite3"

    Mon 11 May 2009

    -(BOOL)addImage:(UIImage *)imageItem{

    int pegId = [self getNewjm_pegID];

    if (!dbOpen) {

    [self openDb];

    }

    NSString *insertProgrammeSql = @"INSERT INTO images (image) VALUES (?)";

    sqlite3_stmt *statement;

    if (sqlite3_prepare_v2(database, [insertProgrammeSql cStringUsingEncoding:NSUTF8StringEncoding], -1, &statement, NULL) == SQLITE_OK) {

    NSData *imageData = UIImagePNGRepresentation(pegItem.albumCover);

    sqlite3_bind_blob(statement, 1, [imageData bytes], [imageData length], SQLITE_TRANSIENT);

    sqlite3_step(statement);

    }

    [self closeDb];

    return YES ...

    read more
  5. "UnZip files on iPhone/iPod"

    Mon 11 May 2009

    //Include files from attached archive

     

    #import "ZipArchive.h"

    NSString *filePath = @"/Users/alex/Test/04/zTest/test.zip";

    ZipArchive *z = [[ZipArchive alloc] init];

     

    [z UnzipOpenFile:filePath];

    [z UnzipFileTo:@"/Users/alex/Test/04" overWrite:YES];

    [z UnzipCloseFile];


    ZipArchive.zip (37.65 kb)

    read more
  6. "play mp3 sound"

    Mon 11 May 2009

    //need to add: AVFoundation.framework

    #import <AVFoundation/AVAudioPlayer.h> 

    NSBundle *mainBundle = [NSBundle mainBundle];

    NSURL *url = [NSURL fileURLWithPath:[mainBundle pathForResource:@"game" ofType:@"mp3"] isDirectory:NO];

     

    AVAudioPlayer *gameSoundTrack = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];

    [gameSoundTrack prepareToPlay];

    [gameSoundTrack play]; 

    read more
  7. "Draw on UIImage"

    Mon 11 May 2009

    -(UIImage *)addCircle:(UIImage *)img radius:(CGFloat)radius latCon:(CGFloat)lat lonCon:(CGFloat)lon{

        int w = img.size.width;

        int h = img.size.height; 

        lon = h - lon;

        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

        CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);

        

    //draw the circle

    CGContextDrawImage(context, CGRectMake(0, 0, w, h ...

    read more
  8. "Add text to image (UIImage)"

    Mon 11 May 2009

    //Add text to UIImage

    -(UIImage *)addText:(UIImage *)img text:(NSString *)text1{

        int w = img.size.width;

        int h = img.size.height

        //lon = h - lon;

        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

        CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);

        

        CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);

        CGContextSetRGBFillColor(context, 0 ...

    read more
  9. "Resize image and keep aspect ratio"

    Mon 11 May 2009

    //Resize image and keep aspect ratio

    -(UIImage *)resizeImage:(UIImage *)image {

    int w = image.size.width;

        int h = image.size.height

    CGImageRef imageRef = [image CGImage];

    int width, height;

    int destWidth = 640;

    int destHeight = 480;

    if(w > h){

    width = destWidth;

    height = h*destWidth/w;

    } else {

    height = destHeight;

    width = w*destHeight/h;

    }

    CGColorSpaceRef ...

    read more
  10. "Move screen when keyboard popup"

    Mon 11 May 2009

    //h file

     

    @interface TestViewController : UIViewController<UITextFieldDelegate> {

        CGFloat animatedDistance;

    }

     

    //m file

     

     

     

    - (void)textFieldDidBeginEditing:(UITextField *)textField{

        

        static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;

        static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;

        static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;

        static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;

        static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 162;

        

        CGRect textFieldRect =

        [self.view.window convertRect:textField.bounds ...

    read more

« Page 12 / 13 »