IOS 纯代码实现界面
程序员文章站
2022-05-12 11:33:37
...
- 移除Main.storyboard关联
- 修改AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
NSLog(@"didFinishLaunchingWithOptions");
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
ViewController *view = [[ViewController alloc]init];
[self.window makeKeyAndVisible];
[self.window setRootViewController:view];
return YES;
}
- 然后就可以在ViewController里实现界面
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIScrollView *scrollView = [[UIScrollView alloc]init];
int ScreenWidth = [[UIScreen mainScreen] bounds].size.width;
int ScreenHeight = [[UIScreen mainScreen] bounds].size.height;
[scrollView setContentSize:CGSizeMake(ScreenWidth, ScreenHeight)];
[self.view addSubview:scrollView];
UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
[img setImage:[UIImage imageNamed:@"welcome"]];
[img setContentMode:UIViewContentModeScaleAspectFill];
[img setUserInteractionEnabled:YES];
[self.view addSubview:img];
}