-
-
Save hachinobu/8995972 to your computer and use it in GitHub Desktop.
CGGeometryクラスの位置やサイズ操作系の関数紹介 ref: http://qiita.com/hachinobu/items/f8ac32870739c7d4eab8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(40, 50, 180, 180)]; | |
view1.backgroundColor = [UIColor redColor]; | |
[self.view addSubview:view1]; | |
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(70, 90, 180, 200)]; | |
view2.backgroundColor = [UIColor yellowColor]; | |
[self.view addSubview:view2]; | |
CGRect unionRect = CGRectUnion(view1.frame, view2.frame); | |
NSLog(@"unionRect:%@", NSStringFromCGRect(unionRect)); | |
UIView *unionView = [[UIView alloc] initWithFrame:unionRect]; | |
unionView.backgroundColor = [UIColor clearColor]; | |
unionView.layer.borderColor = [[UIColor blackColor] CGColor]; | |
unionView.layer.borderWidth = 1.0; | |
[self.view addSubview:unionView]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGFloat amount = 50.0f; | |
CGRect rect = self.view.frame; | |
CGRect sliceRect = CGRectNull; | |
CGRect remainderRect = CGRectNull; | |
CGRectDivide(rect, &sliceRect, &remainderRect, amount, CGRectMaxXEdge); | |
NSLog(@"rect:%@", NSStringFromCGRect(rect)); //rect:{{0, 0}, {320, 568}} | |
NSLog(@"sliceRect:%@", NSStringFromCGRect(sliceRect)); //sliceRect:{{270, 0}, {50, 568}} | |
NSLog(@"remainderRect:%@", NSStringFromCGRect(remainderRect)); //remainderRect:{{0, 0}, {270, 568}} | |
UIView *sliceView = [[UIView alloc] initWithFrame:sliceRect]; | |
sliceView.backgroundColor = [UIColor redColor]; | |
[self.view addSubview:sliceView]; | |
UIView *remainderView = [[UIView alloc] initWithFrame:remainderRect]; | |
remainderView.backgroundColor = [UIColor blueColor]; | |
[self.view addSubview:remainderView]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGFloat amount = 50.0f; | |
CGRect rect = self.view.frame; | |
CGRect sliceRect = CGRectNull; | |
CGRect remainderRect = CGRectNull; | |
CGRectDivide(rect, &sliceRect, &remainderRect, amount, CGRectMaxYEdge); | |
NSLog(@"rect:%@", NSStringFromCGRect(rect)); //rect:{{0, 0}, {320, 568}} | |
NSLog(@"sliceRect:%@", NSStringFromCGRect(sliceRect)); //sliceRect:{{0, 518}, {320, 50}} | |
NSLog(@"remainderRect:%@", NSStringFromCGRect(remainderRect)); //remainderRect:{{0, 0}, {320, 518}} | |
UIView *sliceView = [[UIView alloc] initWithFrame:sliceRect]; | |
sliceView.backgroundColor = [UIColor redColor]; | |
[self.view addSubview:sliceView]; | |
UIView *remainderView = [[UIView alloc] initWithFrame:remainderRect]; | |
remainderView.backgroundColor = [UIColor blueColor]; | |
[self.view addSubview:remainderView]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGFloat amount = 50.0f; | |
CGRect rect = self.view.frame; | |
CGRect sliceRect = CGRectNull; | |
CGRect remainderRect = CGRectNull; | |
CGRectDivide(rect, &sliceRect, &remainderRect, amount, CGRectMinXEdge); | |
NSLog(@"rect:%@", NSStringFromCGRect(rect)); //rect:{{0, 0}, {320, 568}} | |
NSLog(@"sliceRect:%@", NSStringFromCGRect(sliceRect)); //sliceRect:{{0, 0}, {50, 568}} | |
NSLog(@"remainderRect:%@", NSStringFromCGRect(remainderRect)); //remainderRect:{{50, 0}, {270, 568}} | |
UIView *sliceView = [[UIView alloc] initWithFrame:sliceRect]; | |
sliceView.backgroundColor = [UIColor redColor]; | |
[self.view addSubview:sliceView]; | |
UIView *remainderView = [[UIView alloc] initWithFrame:remainderRect]; | |
remainderView.backgroundColor = [UIColor blueColor]; | |
[self.view addSubview:remainderView]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CGFloat amount = 50.0f; | |
CGRect rect = self.view.frame; | |
CGRect sliceRect = CGRectNull; | |
CGRect remainderRect = CGRectNull; | |
CGRectDivide(rect, &sliceRect, &remainderRect, amount, CGRectMinYEdge); | |
NSLog(@"rect:%@", NSStringFromCGRect(rect)); //rect:{{0, 0}, {320, 568}} | |
NSLog(@"sliceRect:%@", NSStringFromCGRect(sliceRect)); //sliceRect:{{0, 518}, {320, 50}} | |
NSLog(@"remainderRect:%@", NSStringFromCGRect(remainderRect)); //remainderRect:{{0, 0}, {320, 518}} | |
UIView *sliceView = [[UIView alloc] initWithFrame:sliceRect]; | |
sliceView.backgroundColor = [UIColor redColor]; | |
[self.view addSubview:sliceView]; | |
UIView *remainderView = [[UIView alloc] initWithFrame:remainderRect]; | |
remainderView.backgroundColor = [UIColor blueColor]; | |
[self.view addSubview:remainderView]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
standardizeRect:{{-100, -50}, {100, 50}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment