Will continuously update some simple and useful iPhone examples here.
1. Logging
In Xcode, click Run > Console to see NSLog statements.
NSLog(@"log: %@", aString);
Nslog(@"log: %f", afloat);
Nslog(@"log: %i", anint);
Nslog(@"log: %f", afloat);
Nslog(@"log: %i", anint);
2. Set an image as background in UIViewController
[1] Use [UIColor colorWithPatternImage]
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
[2] Add an image view to the view, and then send the image view to background.
This method is common used and recommended.
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
imageView.frame = self.view.frame;
[self.view addSubview: imageView];
[self.view sendSubviewToBack: imageView];
[imageView release];
3. Conversion between "NSString" and "char *"
[1] From NSString to char *
myString = [NSString stringWithUTF8String:myChars];
[2] From char * to NSString
myChars = [myString UTF8String];
4. Constant NSString
#define URL_SERVER @"http://www.example.com"
NSString *const URL_1 = URL_SERVER@"/a.php";
NSString *const URL_2 = URL_SERVER@"/b.php";
asd
ReplyDelete