iOS中CGRectDividede中布局用法
2013-06-29 09:43 甘超波 阅读(2029) 评论(0) 编辑 收藏 举报- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSLog(@"view.bouns-->%@",NSStringFromCGRect(self.view.bounds)); [self SplitView3]; } -(void)SplitView{ CGRect bRect,FtRect; //在x上从左到右进行切换矩形,其中左边的原有的矩形,右边是被切割的矩形 CGRectDivide(self.view.bounds, &bRect, &FtRect, 20,CGRectMinXEdge); NSLog(@"bRect-->%@",NSStringFromCGRect(bRect)); NSLog(@"ftRect-->%@",NSStringFromCGRect(FtRect)); // bRect-->{{0, 0}, {20, 460}} // ftRect-->{{20, 0}, {300, 460}} } -(void)SplitView1{ CGRect bRect,FtRect; //在x上从右到左进行切换矩形,其中右边的原有的矩形,左边是被切割的矩形 CGRectDivide(self.view.bounds, &bRect, &FtRect, 20,CGRectMaxXEdge); NSLog(@"bRect-->%@",NSStringFromCGRect(bRect)); NSLog(@"ftRect-->%@",NSStringFromCGRect(FtRect)); // bRect-->{{320-20,0}, {20, 460}} // ftRect-->{{0, 0}, {320-20, 460}} } -(void)SplitView2{ CGRect bRect,FtRect; //在y上从上到下进行切换矩形,其中上边的原有的矩形,下边是被切割的矩形 CGRectDivide(self.view.bounds, &bRect, &FtRect, 20,CGRectMinYEdge); NSLog(@"bRect-->%@",NSStringFromCGRect(bRect)); NSLog(@"ftRect-->%@",NSStringFromCGRect(FtRect)); // bRect-->{{0,0}, {320,20}} // ftRect-->{{0, 20}, {320, 460-320}} } -(void)SplitView3{ CGRect bRect,FtRect; //在x上从下到上进行切换矩形,其中下边的原有的矩形,上边是被切割的矩形 CGRectDivide(self.view.bounds, &bRect, &FtRect, 20,CGRectMaxYEdge); NSLog(@"bRect-->%@",NSStringFromCGRect(bRect)); NSLog(@"ftRect-->%@",NSStringFromCGRect(FtRect)); // bRect-->{{0,460-20}, {320, 20}} // ftRect-->{{0, 0}, {320,460-20}} } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSLog(@"view.bouns-->%@",NSStringFromCGRect(self.view.bounds)); [self SplitView3]; } -(void)SplitView{ CGRect bRect,FtRect; //在x上从左到右进行切换矩形,其中左边的原有的矩形,右边是被切割的矩形 CGRectDivide(self.view.bounds, &bRect, &FtRect, 20,CGRectMinXEdge); NSLog(@"bRect-->%@",NSStringFromCGRect(bRect)); NSLog(@"ftRect-->%@",NSStringFromCGRect(FtRect)); // bRect-->{{0, 0}, {20, 460}} // ftRect-->{{20, 0}, {300, 460}} } -(void)SplitView1{ CGRect bRect,FtRect; //在x上从右到左进行切换矩形,其中右边的原有的矩形,左边是被切割的矩形 CGRectDivide(self.view.bounds, &bRect, &FtRect, 20,CGRectMaxXEdge); NSLog(@"bRect-->%@",NSStringFromCGRect(bRect)); NSLog(@"ftRect-->%@",NSStringFromCGRect(FtRect)); // bRect-->{{320-20,0}, {20, 460}} // ftRect-->{{0, 0}, {320-20, 460}} } -(void)SplitView2{ CGRect bRect,FtRect; //在y上从上到下进行切换矩形,其中上边的原有的矩形,下边是被切割的矩形 CGRectDivide(self.view.bounds, &bRect, &FtRect, 20,CGRectMinYEdge); NSLog(@"bRect-->%@",NSStringFromCGRect(bRect)); NSLog(@"ftRect-->%@",NSStringFromCGRect(FtRect)); // bRect-->{{0,0}, {320,20}} // ftRect-->{{0, 20}, {320, 460-320}} } -(void)SplitView3{ CGRect bRect,FtRect; //在x上从下到上进行切换矩形,其中下边的原有的矩形,上边是被切割的矩形 CGRectDivide(self.view.bounds, &bRect, &FtRect, 20,CGRectMaxYEdge); NSLog(@"bRect-->%@",NSStringFromCGRect(bRect)); NSLog(@"ftRect-->%@",NSStringFromCGRect(FtRect)); // bRect-->{{0,460-20}, {320, 20}} // ftRect-->{{0, 0}, {320,460-20}} } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. }
//第一个参数,原来矩形的 第二参数在原来矩形中加边距 ,形成新的矩形 CGRect padding= UIEdgeInsetsInsetRect(self.view.bounds, UIEdgeInsetsMake(10, 10, 20, 10)); NSLog(@"paddingview-->%@",NSStringFromCGRect(padding)); UIView *paddingview=[[UIView alloc] initWithFrame:padding]; paddingview.backgroundColor=[UIColor yellowColor]; [self.view addSubview:paddingview]; [paddingview release]; //{{0, 0}, {320, 460}} // paddingview-->{{10, 10}, {300, 430}}
//第一个参数,原来矩形的 第二参数在原来矩形中加边距 ,形成新的矩形 CGRect padding= UIEdgeInsetsInsetRect(self.view.bounds, UIEdgeInsetsMake(10, 10, 20, 10)); NSLog(@"paddingview-->%@",NSStringFromCGRect(padding)); UIView *paddingview=[[UIView alloc] initWithFrame:padding]; paddingview.backgroundColor=[UIColor yellowColor]; [self.view addSubview:paddingview]; [paddingview release]; //{{0, 0}, {320, 460}} // paddingview-->{{10, 10}, {300, 430}}
目前我正在专注NLP,请立刻加微信/QQ号 546611623, 免费送你原创《NLP高级执行师》高清视频