Last active
August 29, 2015 13:55
-
-
Save RonGafni/8769656 to your computer and use it in GitHub Desktop.
Objective-C draw simple Analog Clock
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
-(void)clockHoursWithCenter:(CGPoint )aCenter view:(UIView *)view radius:(NSInteger)radius | |
{ | |
NSArray *hoursArray = [[NSArray alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", nil]; | |
UIView *aView = [[UIView alloc]init]; | |
aView.frame = CGRectMake(aCenter.x - aView.frame.size.width/2, aCenter.y - aView.frame.size.height/2, 10, 10); | |
[UIView animateWithDuration:.3 animations:^{ | |
for (NSString *hour in hoursArray) | |
{ | |
UIButton *hourButton = [[UIButton alloc]init]; | |
int hourNumber = [hour intValue]; | |
CGPoint center = aCenter; | |
center.x = aView.bounds.size.width/2 + radius*sin(2*M_PI/12*hourNumber); | |
center.y = aView.bounds.size.height/2 - radius*cos(2*M_PI/12*hourNumber); | |
[hourButton setTitle:hour forState:UIControlStateNormal]; | |
[hourButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal]; | |
hourButton.frame = CGRectMake(center.x - hourButton.frame.size.width/2,center.y - hourButton.frame.size.height/2 , 25, 25); | |
[aView addSubview:hourButton]; | |
[view addSubview:aView]; | |
} | |
}]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment