まず、ステータスバー含まない端末画面のサイズとステータスバーの高さを取得し、UIViewの幅と高さを計算しました。ステータスバーの高さはUIApplicationのstatusBarFrameプロパティを参照して取得できるようです。
関連:iOS端末画面のwidthとheightを取得する
次にUIWindowにUIViewを4つ追加しました。UIWindowやUIViewが持つaddSubviewメソッドを利用することで、UIWindowにUIViewを追加したり、UIViewにUIViewを追加したりできるようです。
プログラム
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect aFrame = [[UIScreen mainScreen] applicationFrame];
float windowWidth = aFrame.size.width;
float windowHeight = aFrame.size.height;
float statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
float viewWidth = windowWidth / 2;
float viewHeight = windowHeight / 2;
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
UIView* leftUpView = [[UIView alloc] initWithFrame:CGRectMake(0, statusBarHeight, viewWidth, viewHeight)];
leftUpView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.6];
[self.window addSubview:leftUpView];
UIView* rightUpView = [[UIView alloc] initWithFrame:CGRectMake(windowWidth / 2, statusBarHeight, viewWidth, viewHeight)];
rightUpView.backgroundColor = [UIColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:0.6];
[self.window addSubview:rightUpView];
UIView* leftDownView = [[UIView alloc] initWithFrame:CGRectMake(0, statusBarHeight + windowHeight / 2, viewWidth, viewHeight)];
leftDownView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:0.6];
[self.window addSubview:leftDownView];
UIView* rightDownView = [[UIView alloc] initWithFrame:CGRectMake(windowWidth / 2, statusBarHeight + windowHeight / 2, viewWidth, viewHeight)];
rightDownView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:0.6];
[self.window addSubview:rightDownView];
[self.window makeKeyAndVisible];
return YES;
}

0 件のコメント:
コメントを投稿