#import <UIKit/UIKit.h>
// Application delegate
@interface Simple : NSObject <UIApplicationDelegate>
{
}
@end
@implementation Simple
- (void)applicationDidFinishLaunching: (UIApplication*)application
{
UIWindow* window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
[window setBackgroundColor: [UIColor orangeColor]];
[window makeKeyAndVisible];
}
@end
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"Simple");
[pool release];
return retVal;
}
int retVal = UIApplicationMain(argc, argv, nil, @"Simple");
- (void)applicationDidFinishLaunching: (UIApplication*)application
{
UIWindow* window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
[window setBackgroundColor: [UIColor orangeColor]];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDoesRelativeDateFormatting: YES];
[formatter setDateStyle: NSDateFormatterLongStyle];
[formatter setTimeStyle: NSDateFormatterShortStyle];
NSDate *now = [NSDate date];
NSString *formattedDateTime = [formatter stringFromDate: now];
NSLog(@"Formatted Date: %@", formattedDateTime);
[formatter release];
[window makeKeyAndVisible];
}
Deleted xib-file does not mean that my program cannot have a GUI. Next code snippet demonstrate a GUI application:
#import <UIKit/UIKit.h>
@interface SimpleController : UIViewController
{
}
@end
@implementation SimpleController
- (id)init
{
if (self = [super init])
{
self.title = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
}
return self;
}
- (void)loadView
{
// Load an application image and set it as the primary view
UIImageView* contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[contentView setImage:[UIImage imageNamed:@"Abackground.png"]];
// Provide support for auto-rotation and resizing
contentView.autoresizesSubviews = YES;
contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
// Assign the view to the view controller
self.view = contentView;
[contentView release];
}
-(void) dealloc
{
[super dealloc];
}
@end
@interface Simple : NSObject <UIApplicationDelegate>
{
}
@end
@implementation Simple
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nav = [[UINavigationController alloc]
initWithRootViewController:[[SimpleController alloc] init]];
[window addSubview:nav.view];
[window makeKeyAndVisible];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
- (void)dealloc
{
[super dealloc];
}
@end
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"Simple");
[pool release];
return retVal;
}
This code defines the simplest view controller (SimpleController class) which creates a UIImageView and set an image to it. Here is the application screenshot:
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)