#import <UIKit/UIKit.h>
#import "ContainerView.h"
@ interface DemoViewController : UIViewController
{
ContainerView *containerView;
}
@end
* This source code was highlighted with Source Code Highlighter .
- ( void )loadView
{
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
UIView *contentView = [[UIView alloc] initWithFrame:screenRect];
contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
contentView.backgroundColor = [UIColor blueColor];
self.view = contentView;
[contentView release];
containerView = [[ContainerView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, screenRect.size.height)];
containerView.backgroundColor = [UIColor blueColor];
containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:containerView];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.frame = CGRectZero;
[button1 setTitle: @"Object 1" forState:UIControlStateNormal];
button1.tag = 1001;
[containerView addSubview:button1];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button2.frame = CGRectZero;
[button2 setTitle: @"Object 2" forState:UIControlStateNormal];
button2.tag = 1002;
[containerView addSubview:button2];
UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button3.frame = CGRectZero;
[button3 setTitle: @"Object 3" forState:UIControlStateNormal];
button3.tag = 1003;
[containerView addSubview:button3];
UIButton *button4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button4.frame = CGRectZero;
[button4 setTitle: @"Object 4" forState:UIControlStateNormal];
button4.tag = 1004;
[containerView addSubview:button4];
}
* This source code was highlighted with Source Code Highlighter .
- ( void )layoutSubviews
{
[super layoutSubviews];
if (self.frame.size.width == 768)
{
UIView *view = [self viewWithTag:1001];
view.frame = CGRectMake(184, 100, 400, 150);
view = [self viewWithTag:1002];
view.frame = CGRectMake(184, 300, 400, 150);
view = [self viewWithTag:1003];
view.frame = CGRectMake(184, 500, 400, 150);
view = [self viewWithTag:1004];
view.frame = CGRectMake(184, 700, 400, 150);
}
else
{
UIView *view = [self viewWithTag:1001];
view.frame = CGRectMake(74, 100, 400, 150);
view = [self viewWithTag:1002];
view.frame = CGRectMake(550, 100, 400, 150);
view = [self viewWithTag:1003];
view.frame = CGRectMake(74, 400, 400, 150);
view = [self viewWithTag:1004];
view.frame = CGRectMake(550, 400, 400, 150);
}
}
* This source code was highlighted with Source Code Highlighter .
if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]))
* This source code was highlighted with Source Code Highlighter .
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
controller = [[DemoViewController alloc] initWithNibName:nil bundle:nil];
window.backgroundColor = [UIColor blueColor];
[window addSubview:controller.view];
[window makeKeyAndVisible];
return YES;
}
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/95028/
All Articles