有一个AppDelegate
和一个MainViewController
。在创建时,MainViewController
设置背景图像并应将其显示在. 差不多就是这样,但我看不到。UIButton
AppDelegate
MainViewController
UIButton
仅出于对齐目的,我在 IB 中创建IBOutlet
并连接了按钮。
主视图控制器.h
@property (strong, nonatomic) IBOutlet UIButton *searchBtn;
主视图控制器.m
@synthesize searchBtn;
AppDelegate.m
@synthesize mainVC;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// ViewController > setup:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.mainVC = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
self.window.rootViewController = self.mainVC;
self.window.backgroundColor = [UIColor whiteColor];
// Buttons > Set background images:
[self.mainVC.searchBtn setImage:[UIImage imageNamed:@"search.png"] forState:UIControlStateNormal];
[self.mainVC.view addSubview:self.mainVC.searchBtn];
[self.window makeKeyAndVisible];
return YES;
}