NSHTTPURLResponse * response; NSError * error; NSMutableURLRequest request; request = [[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://google.com/"] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60] autorelease]; NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; NSLog(@"%@", [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]); NSArray * all = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@"http://google.com/"]]; NSLog ...
"Create openGL texture"
- (void)createGLTexture:(GLuint *)texName fromCGImage:(CGImageRef)img
{
GLubyte *spriteData = NULL;
CGContextRef spriteContext;
GLuint imgW, imgH, texW, texH;
imgW = CGImageGetWidth(img);
imgH = CGImageGetHeight(img);
// Find smallest possible powers of 2 for our texture dimensions
for (texW = 1; texW < imgW; texW *= 2) ;
for (texH = 1; texH < imgH; texH *= 2) ;
// Allocated memory needed ...
read more"Resize UITableView to fit toolbar"
CGFloat toolbarHeight = 50;
CGRect mainViewBounds = self.view.bounds;
[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),
CGRectGetWidth(mainViewBounds),
toolbarHeight)];
UIView *footerView = [[[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds),
CGRectGetWidth(mainViewBounds),
toolbarHeight+5)] autorelease];
tableView = [[UITableView alloc]
initWithFrame:CGRectMake(mainViewBounds.origin.x, mainViewBounds.origin.y, mainViewBounds.size.width ...
read more"Save image to image library"
-(void)savePictureToLibrary{
UIImage *img = [[UIImage imageNamed:@"image.png"];
UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), self);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
NSString *str = @"Saved!!!";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Saved." message:str delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
read more"Create UIButton/button with images"
UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);
[playButton setTitle:@"Play" forState:UIControlStateNormal];
playButton.backgroundColor = [UIColor clearColor];
[playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal ...
read more"Use image for background for UIView"
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"whiteBackground.png"]];
read more"Method for action (selector)"
"Check if device connected to the Internet"
#import <SystemConfiguration/SCNetworkReachability.h>
#include <netinet/in.h>
- (BOOL) connectedToNetwork
{
// Create zero addy
struct sockaddr_in zeroAddress;
bzero(&zeroAddress, sizeof(zeroAddress));
zeroAddress.sin_len = sizeof(zeroAddress);
zeroAddress.sin_family = AF_INET;
// Recover reachability flags
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
SCNetworkReachabilityFlags flags;
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
CFRelease(defaultRouteReachability);
if (!didRetrieveFlags)
{
printf("Error ...
read more"Alert (UIAlertView) with text field (UITextField)"
// open a alert with text field, OK and cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send Email" message:@" "
delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Send", nil];
CGRect frame = CGRectMake(14, 45, 255, 23);
if(!emailField) {
emailField = [[UITextField alloc] initWithFrame:frame];
emailField.borderStyle = UITextBorderStyleBezel;
emailField.textColor = [UIColor blackColor];
emailField.textAlignment = UITextAlignmentCenter;
emailField ...
read more"Generate PDF on iPhone"
//Create empty PDF context on iPhone for later randering in it
-(CGContextRef) createPDFContext:(CGRect)inMediaBox path:(CFStringRef) path
{
CGContextRef myOutContext = NULL;
CFURLRef url;
url = CFURLCreateWithFileSystemPath (NULL, // 1
path,
kCFURLPOSIXPathStyle,
false);
if (url != NULL) {
myOutContext = CGPDFContextCreateWithURL (url,// 2
&inMediaBox,
NULL);
CFRelease(url);// 3
}
return myOutContext;// 4
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask ...
read more