Detect the specific device touch model


[[UIDevice currentDevice] platformType]   // ex: UIDevice4GiPhone
[[UIDevice currentDevice] platformString] // ex: @"iPhone 4G"

Clear UIWebView content

[webView loadHTMLString:@"<html><head></head><body></body></html>" baseURL:nil];

Define Maximum Characters in Textfield


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 
{
    NSUInteger newLength = [textField.text length] + [string length] - range.length;
    return (newLength > 80) ? NO : YES;
}

Change UITextField’s Placeholder Color

[self.MyTextField setValue:[UIColor darkGrayColor] forKeyPath:@"_placeholderLabel.textColor"];

Set Rounded Corner to Image


UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];


// You can even add a border
[l setBorderWidth:4.0];
[l setBorderColor:[[UIColor blueColor] CGColor]];

How to post Tweets with iOS5


  1. Add Twitter framework to your project
  2. #import "Twitter/TWTweetComposeViewController.h"
  3. Add this code:
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
    
    [twitter setInitialText:@"It's really that simple!"];
    [twitter addImage:[UIImage imageNamed:@"twitter.png"]];

    [self presentViewController:twitter animated:YES completion:nil];
       
    twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {
        
        if(res == TWTweetComposeViewControllerResultDone)
        {
            
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Succes!" message:@"Your Tweet was posted succesfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            
            [alertView show];
            
            
        }else if(res == TWTweetComposeViewControllerResultCancelled)
        {
            
            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your Tweet was not posted" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            
            [alertView show];
            
        }
        
        [self dismissModalViewControllerAnimated:YES];
        
    };

Disable or Hide Button in UIActionSheet


UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Share"
delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
otherButtonTitles:@"Send Message (SMS)", @"Send E-Mail", @"Print", @"Twitter", nil];
    [actionSheet showInView:self.view];
    for(UIView *v in [actionSheet subviews])
    {
        if([[v description] hasPrefix: @"<UIThreePartButton"] )
        {
            if ([v respondsToSelector:@selector(title)])
            {
                NSString* title = [v performSelector:@selector(title)];
                if ([title isEqualToString:@"Twitter"])
                {
                    //v.hidden = YES;
                    ((UIButton*)v).enabled = NO;
                }
            }
        }
    }
    [actionSheet release];