首页 > 代码库 > 秒表---框架搭建
秒表---框架搭建
案例描写叙述:实现下图所看到的的效果。被时间函数什么的搞乱了,就仅仅搭了一个框架,详细实现的计时功能等整好了一起上传~~~ (看看这引入的n个头文件,俺也是醉了~)
效果图:
详细代码:
#import "JRTabBarController.h"
#import "MiaoBiaoNavigationController.h"
#import "MiaoBiaoViewController.h"
#import "JSQNavigationController.h"
#import "JSQViewController.h"
#import "NaoZhongViewController.h"
#import "NZNavigationController.h"
#import "SJSZNavigationController.h"
#import "SJSZViewController.h"
#define kLeftSpace 30 //左边距
#define kRightSpace 30 //右边距
#define kMiddleSpace 40 //中间空白距
#define kW self.view.frame.size.width
#define kH self.view.frame.size.height
@interface JRTabBarController ()
//点击button切换图片
@property (nonatomic,strong)NSMutableArray * buttonArray;
@end
@implementation JRTabBarController
#pragma mark - 懒载入
- (NSMutableArray *)buttonArray
{
if (_buttonArray==nil)
{
_buttonArray=[NSMutableArrayarray];
}
return _buttonArray;
}
- (void)viewDidLoad {
[superviewDidLoad];
self.view.backgroundColor=[UIColorwhiteColor];
//1.载入控制器
[self_loadVC];
//2.自己定义TabBar
[self_makeTabBar];
}
#pragma mark - 载入控制器
- (void) _loadVC
{
//创建视图控制器
//世界时间
SJSZViewController * sjVC=[[SJSZViewControlleralloc]init];
SJSZNavigationController * vc1=[[SJSZNavigationControlleralloc]initWithRootViewController:sjVC];
//闹钟
NaoZhongViewController * nzVC=[[NaoZhongViewControlleralloc]init];
NZNavigationController * vc2=[[NZNavigationControlleralloc]initWithRootViewController:nzVC];
//秒表
MiaoBiaoViewController * mbVC=[[MiaoBiaoViewControlleralloc]init];
// mbVC.view.backgroundColor=[UIColor redColor];
MiaoBiaoNavigationController * vc3=[[MiaoBiaoNavigationControlleralloc]initWithRootViewController:mbVC];
//计时器
JSQViewController * jsqVC=[[JSQViewControlleralloc]init];
JSQNavigationController * vc4=[[JSQNavigationControlleralloc]initWithRootViewController:jsqVC];
self.viewControllers=@[vc1,vc2,vc3,vc4];
self.selectedViewController=vc3;
}
#pragma mark - 自己定义TabBar
- (void) _makeTabBar
{
//1.定制TabBar
UIView * bgView=[[UIViewalloc] initWithFrame:CGRectMake(0,kH-49,kW,49)];
bgView.backgroundColor=[UIColorwhiteColor];
[self.viewaddSubview:bgView];
//2.定制button
CGFloat space=(kW-kLeftSpace-kRightSpace-3*kMiddleSpace)/4; //每一个小button的宽度
for (int i=0; i<4; i++)
{
UITabBarButton * button=[[UITabBarButtonalloc]initWithFrame:CGRectMake(kLeftSpace+i*space+i*kMiddleSpace,0, space, 49)];
button.backgroundColor=[UIColorwhiteColor];
button.tag=i;
NSString * imageName=[NSStringstringWithFormat:@"%d",i+1];
[button setImage:[UIImageimageNamed:imageName] forState:UIControlStateNormal];
if (i==2)
{
NSString * imageName=[NSStringstringWithFormat:@"0%d",i+1];
[button setImage:[UIImageimageNamed:imageName] forState:UIControlStateNormal];
}
[button addTarget:selfaction:@selector(changeImage:)forControlEvents:UIControlEventTouchUpInside];
button.delegateMe=self;
[self.buttonArrayaddObject:button];
[bgViewaddSubview:button];
}
}
- (void) changeImage:(UITabBarButton *) button
{
for (int i=0; i<4; i++)
{
if (i!=button.tag)
{
NSString * imageName=[NSStringstringWithFormat:@"%d",i+1];
UIButton *butt=self.buttonArray[i];
[butt setImage:[UIImageimageNamed:imageName] forState:UIControlStateNormal];
}
}
[button.delegateMechangePage:button.tag];
NSString * imageName=[NSStringstringWithFormat:@"0%d",(int)(button.tag+1)];
[button setImage:[UIImageimageNamed:imageName] forState:UIControlStateNormal];
}
- (void)changePage:(NSInteger)index
{
[UIViewbeginAnimations:nilcontext:nil];
[UIViewcommitAnimations];
self.selectedIndex=index;
}
@end
#import "MiaoBiaoViewController.h"
#define kW self.view.frame.size.width
#define kH self.view.frame.size.height
@interface MiaoBiaoViewController ()
{
NSDateFormatter *fomatter;
NSInvocationOperation *operation1;
NSInvocationOperation *operation2;
}
//@property (nonatomic,weak)
@end
@implementation MiaoBiaoViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.title=@"秒表";
//小时钟
UILabel * conLabel=[[UILabelalloc]initWithFrame:CGRectMake(267,85, 110, 50)];
// conLabel.backgroundColor=[UIColor redColor];
conLabel.text=@"00:00.00";
conLabel.font=[UIFontfontWithName:nilsize:25];
[self.viewaddSubview:conLabel];
//秒表
UILabel * ctLabel=[[UILabelalloc]initWithFrame:CGRectMake(0,160,kW,150)];
// ctLabel.backgroundColor=[UIColor redColor];
ctLabel.text=@"00:00.00";
ctLabel.textAlignment=NSTextAlignmentCenter;
ctLabel.font=[UIFontfontWithName:nilsize:75];
[self.viewaddSubview:ctLabel];
//下方视图
UIView * bView=[[UIViewalloc]initWithFrame:CGRectMake(0,350,kW,300)];
bView.backgroundColor=[UIColorcolorWithRed:0.1green:0.1blue:0.1alpha:0.1];
[self.viewaddSubview:bView];
//開始停止button
UIButton * ssButton=[[UIButtonalloc]initWithFrame:CGRectMake((kW-200)/3,30, 100, 100)];
ssButton.backgroundColor=[UIColorwhiteColor];
ssButton.layer.cornerRadius=50;
[ssButton setTitle:@"開始"forState:UIControlStateNormal];
[ssButton setTitle:@"停止"forState:UIControlStateSelected];
[ssButton setTitleColor:[UIColorredColor] forState:UIControlStateNormal];
[ssButton setTitleColor:[UIColorgrayColor] forState:UIControlStateSelected];
ssButton.tag=1;
[ssButton addTarget:selfaction:@selector(StartStop:)forControlEvents:UIControlEventTouchUpInside];
[bViewaddSubview:ssButton];
//计次button
UIButton * jcButton=[[UIButtonalloc]initWithFrame:CGRectMake(((kW-200)/3)*2+100,30, 100, 100)];
jcButton.backgroundColor=[UIColorwhiteColor];
jcButton.layer.cornerRadius=50;
[jcButton setTitle:@"计次"forState:UIControlStateNormal];
[jcButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];
[jcButton addTarget:selfaction:@selector(CountNum)forControlEvents:UIControlEventTouchUpInside];
[bViewaddSubview:jcButton];
}
- (void)StartStop:(UIButton *) button
{
button.selected = !button.selected;
NSLog(@"%i", button.selected);
NSLog(@"asdasdasd");
}
- (void)CountNum
{
NSLog(@"////////");
}
@end
秒表---框架搭建