#define CRM(x, y, width, height) CGRectMake(x, y, width, height)
#define CPM(x, y) CGPointMake(x, y)
#import "DataiViewController.h"
@interface ViewController ()
@end
@implementation ViewController
//初始化方法,系统创建的视图控制器独有的方法
-(instancetype)initWithCoder:(NSCoder *)coder{
self = [super initWithCoder:coder];
if (self) {
}
return self;
}
#pragma mark -- 视图控制器的生命周期方法
//视图即将出现的时候调用
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSLog(@"%@",NSStringFromSelector(_cmd));
}
//视图已经出现的时候调用
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"%@",NSStringFromSelector(_cmd));
}
//视图即将消失时调用
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
NSLog(@"%@",NSStringFromSelector(_cmd));
}
//视图已经消失时调用
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
NSLog(@"%@",NSStringFromSelector(_cmd));
}
- (void)viewDidLoad {
[super viewDidLoad];
//视图加载完成时调用
NSLog(@"%@",NSStringFromSelector(_cmd));
#pragma mark -UILabel
// 当前视图控制器
UILabel *markLabel = [[UILabel alloc]initWithFrame:CRM(0, 10, CGRectGetWidth(self.view.bounds), 80)];
markLabel.backgroundColor = [UIColor redColor];
markLabel.text = @"ViewController";
markLabel.textAlignment = NSTextAlignmentCenter;
markLabel.font = [UIFont systemFontOfSize:20];
markLabel.textColor = [UIColor yellowColor];
[self.view addSubview:markLabel];// 实际效果看图-1.png
#pragma mark -UIButton
//下一页
UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeSystem];
nextButton.bounds = CRM(0, 0, 80, 30);
nextButton.center = CPM(CGRectGetMidX(self.view.bounds), CGRectGetMaxY(self.view.frame)-50);
[nextButton setTitle:@"下一页" forState:UIControlStateNormal];
[nextButton addTarget:self action:@selector(nextbuttonT:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nextButton];// 实际效果看图-2.png
#pragma mark -UIView
UIView *redview = [[UIView alloc]initWithFrame:CRM(40, 200, 150, 150)];
redview.backgroundColor =[UIColor redColor];
[self.view addSubview:redview];
UIView *blackview = [[UIView alloc]initWithFrame:CRM(110, 270, 150, 150)];
blackview.backgroundColor = [UIColor blackColor];
[self.view addSubview:blackview];// 实际效果看图-3.png
// 视图层级
[self.view bringSubviewToFront:redview];
// [self.view sendSubviewToBack:blackview];
}
-(void)nextbuttonT:(UIButton *)sender{
DataiViewController *datai = [[DataiViewController alloc]init];
//推送效果
// detailViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
// 模态推送
[self presentViewController:datai animated:YES completion:nil];
}
@end
》》》》》》》》创建DataiViewController
#import "DataiViewController.h"
#define CRM(x, y, width, height) CGRectMake(x, y, width, height)
#define CPM(x, y) CGPointMake(x, y)
//字符串常量
static NSString *const mycontent = @"hhh";
@interface DataiViewController ()
@end
@implementation DataiViewController
//初始化方法
-(instancetype)init{
self = [super init];
if (self) {
NSLog(@"%@",NSStringFromSelector(_cmd));
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
#pragma mark -UILabel
// 当前视图控制器
UILabel *markLabel = [[UILabel alloc]initWithFrame:CRM(0, 10, CGRectGetWidth(self.view.bounds), 80)];
markLabel.backgroundColor = [UIColor redColor];
markLabel.text = @"ViewController";
markLabel.textAlignment = NSTextAlignmentCenter;
markLabel.font = [UIFont systemFontOfSize:20];
markLabel.textColor = [UIColor yellowColor];
[self.view addSubview:markLabel];
// 返回
UIButton *backbutton = [UIButton buttonWithType:UIButtonTypeSystem];
backbutton.frame = CRM(10, 100, 80, 30);
[backbutton setTitle:@"返回" forState:UIControlStateNormal];
[backbutton addTarget:self action:@selector(backbutton:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backbutton];
#pragma mark - UIImageView
UIImageView *headimageview = [[UIImageView alloc]initWithFrame:CRM(10, 200, 150, 150)];
headimageview.image = [UIImage imageNamed:@"Steve Jobs"];// 加载图片
headimageview.layer.cornerRadius = 75;//设置圆角
headimageview.clipsToBounds = YES;
headimageview.layer.shadowColor = [UIColor blackColor].CGColor;//投影颜色,需要强转。.CGColor
headimageview.layer.shadowOpacity = 0.8;//投影透明度
headimageview.layer.shadowOffset = CSM(3, 3);//投影偏移量
headimageview.layer.borderColor = [UIColor redColor].CGColor;//边框颜色
headimageview.layer.borderWidth = 2;//边框宽度
[self.view addSubview:headimageview];//实际效果看图-4.png
UILabel *namelabel = [[UILabel alloc]initWithFrame:CRM(CGRectGetMaxX(headimageview.frame) + 20, CGRectGetMinY(headimageview.frame), 150, 20)];
namelabel.text = @"AAA";
namelabel.font = [UIFont systemFontOfSize:20];
[self.view addSubview:namelabel];
UILabel *yearlabel = [[UILabel alloc]initWithFrame:CRM(CGRectGetMaxX(headimageview.frame) + 20, CGRectGetMaxY(namelabel.frame) + 10, 150, 20)];
yearlabel.text = @"1955 - 2011";
yearlabel.font = [UIFont systemFontOfSize:20];
[self.view addSubview:yearlabel];
#pragma mark -多行文本框UITextView
UITextView *contentTextView = [[UITextView alloc]initWithFrame:CRM(CGRectGetMinX(headimageview.frame), CGRectGetMaxY(headimageview.frame) + 20, 300, 100)];
contentTextView.text = @"dasdas";
contentTextView.editable = NO;//禁用编辑
[self.view addSubview:contentTextView];//实际效果看图-5.png
}
-(void)backbutton:(UIButton*)sender{
// 返回上一页
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
@end