欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

IOS 纯代码实现界面

程序员文章站 2022-05-12 11:33:37
...
  1. 移除Main.storyboard关联
    IOS 纯代码实现界面

IOS 纯代码实现界面

  1. 修改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;
}
  1. 然后就可以在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];
}