What I would like to do is to create UIImageView without storyboard, but failed to let it show. At first I deleted storyboard
, LaunchScreen.xib
and Main StoryBoard file base name
from info.plist. and then what I created is as follows:
AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor greenColor];
[self.window makeKeyAndVisible];
return YES;
}
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *imageData =[UIImage imageNamed:@"aaa.png"];
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 30, 100, 100)];
myImage.image = imageData;
[self.view addSubview:myImage];
}
I am a beginner and couldn't find any solution. Does anybody know how to solve this? Thank you in advance.
Xcode 6.4
OSX 10.10.5
You just need to set your window's root view controller to an instance of ViewController
self.window.rootViewController = [[ViewController alloc] init];
You'll also have to import ViewController.h at the top of your AppDelegate file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.