Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Create a UIImageView with the circle image and center it in the main view.
- UIImageView *container = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0f, 300.0f, 300.0f)];
- container.image = [UIImage imageNamed:@"CircleInSquare"];
- container.center = CGPointMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0);
- [self.view addSubview:container];
- // Calculate the angle between each label based on the number of labels.
- int numberOfSections = 9;
- CGFloat angleSize = 2*M_PI/numberOfSections;
- // Each label gets the exact same inital frame, but a different transform is applied to space them around the circle.
- for (int i = 0; i < numberOfSections; ++i) {
- UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 50.0f)];
- sectionLabel.text = [NSString stringWithFormat:@"%i", i];
- sectionLabel.font = [UIFont systemFontOfSize:50.0];
- sectionLabel.textColor = [UIColor whiteColor];
- sectionLabel.backgroundColor = [UIColor clearColor];
- //sectionLabel.backgroundColor = [UIColor colorWithRed:1.0f green:0.0f blue:0.2f alpha:0.5f];
- /***** Here's the most important part: changing the anchorPoint, adjusting the position accordingly, and applying rotation ****/
- sectionLabel.layer.anchorPoint = CGPointMake(1.0f, 0.5f);
- sectionLabel.layer.position = CGPointMake(container.bounds.size.width/2.0, container.bounds.size.height/2.0); // places anchorPoint of each label directly in the center of the circle.
- sectionLabel.transform = CGAffineTransformMakeRotation(angleSize*i);
- [container addSubview:sectionLabel];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement