1. "Create screenshot in runtime (inside UIView)"

    Sat 07 November 2009

    UIGraphicsBeginImageContext(self.bounds.size);

    [self.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    read more
  2. "Get list of files"

    Sat 07 November 2009

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

     

    //try to get list of files from new folder

    NSDirectoryEnumerator *direnum = [[NSFileManager defaultManager]

      enumeratorAtPath:documentsDirectory];

     

    NSString *pname;

    while (pname = [direnum nextObject])

    {

    if ([[pname pathExtension] isEqualToString:@"rtfd"])

    {

    /* don't enumerate this directory */

    [direnum skipDescendents];

    }

    else

    {

    /* ...process file here... */

    NSLog(pname);

    }

    }

    read more
  3. "Hide keyboard when pressing Done"

    Mon 26 October 2009

    // You need to add this method to your controller class

    - (BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];

    return YES;

    }


    read more
  4. "Flip UIView"

    Fri 16 October 2009

    -(IBAction)flipAction{

    NSLog(@"flip");

    [UIView beginAnimations:nil context:NULL];

    [UIView setAnimationDuration:1];

    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight

      forView:self.view cache:YES];

    if ([discoView superview]){

    [discoView removeFromSuperview];

    [termsView addSubview:flipButton];

    [self.view addSubview:termsView];

    }

    else

    {

    [termsView removeFromSuperview];

    [self.view addSubview:discoView];

    [discoView addSubview:flipButton];

    }

    [UIView commitAnimations];

    }


    read more
  5. "Get pixel information from UIImage"

    Sun 04 October 2009

    UIImage *uiImage = [UIImage imageNamed:@"myimage.png"];

    CGImageRef image = uiImage.CGImage;

    NSUInteger width = CGImageGetWidth(image);

    NSUInteger height = CGImageGetHeight(image);

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

    UInt8 * rawData = malloc(height * width * 4);

     

    int bytesPerPixel = 4;

    int bytesPerRow = bytesPerPixel * width;

     

    NSUInteger bitsPerComponent = 8;

    CGContextRef context1 = CGBitmapContextCreate(

    rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace,

    kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big

    );

    CGColorSpaceRelease(colorSpace ...

    read more
  6. "Shake detect"

    Wed 23 September 2009

    #define kAccelerationThreshold 2.2

     

     

    //Somewhere in initialization

    UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];

    accel.delegate = self;

    accel.updateInterval = 1.0f/10.0f;

     

    - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

    if (fabsf(acceleration.x) > kAccelerationThreshold || fabsf(acceleration.y) > kAccelerationThreshold || fabsf(acceleration.z) > kAccelerationThreshold) {

    NSLog(@"Shaking!!!");

    }

    read more
  7. "Push/go/navigate to next ViewController"

    Wed 09 September 2009

     

    if (addBracket == nil) {

    BracketAddEdit *aBracket = [[BracketAddEdit alloc] initWithNibName:nil bundle:nil];

    self.addBracket = aBracket;

    [aBracket release];

    }

     

    [[self navigationController] pushViewController:addBracket animated:YES];

     

    read more
  8. "Get IP address of iPhone"

    Mon 07 September 2009

    /*

     *  IPAdress.h

     *

     *

     */

     

    #define MAXADDRS 32

     

    extern char *if_names[MAXADDRS];

    extern char *ip_names[MAXADDRS];

    extern char *hw_addrs[MAXADDRS];

    extern unsigned long ip_addrs[MAXADDRS];

     

    // Function prototypes

     

    void InitAddresses();

    void FreeAddresses();

    void GetIPAddresses();

    void GetHWAddresses();

     

    /*

     *  IPAddress.c

     *

     */

     

    #include "IPAddress.h"

     

    #include <stdio.h>

    #include <stdlib.h>

    #include <string.h>

    #include <unistd.h>

    #include ...

    read more
  9. "User Script to generate properties from instance variables"

    Wed 02 September 2009

    #!/usr/bin/python

     

     

    # Takes a header file with one or more instance variables selected

    # and creates properties and synthesize directives for the selected properties.

     

    # Accepts google-style instance variables with a tailing underscore and

    # creates an appropriately named property without underscore.

     

    # Xcode script options should be as follows:

    # Entire Document

    # Home ...

    read more

« Page 6 / 13 »