案例描写叙述:实现下图所看到的的效果。被时间函数什么的搞乱了,就仅仅搭了一个框架,详细实现的计时功能等整好了一起上传~~~ (看看这引入的n个头文件,俺也是醉了~)
效果图:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfMjczNjQ0MzE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" width="250" height="350" >
详细代码:
#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=[NSMutableArray
array];
}
return
_buttonArray;
}
- (void)viewDidLoad {
[super
viewDidLoad];
self.view.backgroundColor=[UIColor
whiteColor];
//1.载入控制器
[self
_loadVC];
//2.自己定义TabBar
[self
_makeTabBar];
}
#pragma mark - 载入控制器
- (void) _loadVC
{
//创建视图控制器
//世界时间
SJSZViewController * sjVC=[[SJSZViewController
alloc]init];
SJSZNavigationController * vc1=[[SJSZNavigationController
alloc]initWithRootViewController:sjVC];
//闹钟
NaoZhongViewController * nzVC=[[NaoZhongViewController
alloc]init];
NZNavigationController * vc2=[[NZNavigationController
alloc]initWithRootViewController:nzVC];
//秒表
MiaoBiaoViewController * mbVC=[[MiaoBiaoViewController
alloc]init];
// mbVC.view.backgroundColor=[UIColor redColor];
MiaoBiaoNavigationController * vc3=[[MiaoBiaoNavigationController
alloc]initWithRootViewController:mbVC];
//计时器
JSQViewController * jsqVC=[[JSQViewController
alloc]init];
JSQNavigationController * vc4=[[JSQNavigationController
alloc]initWithRootViewController:jsqVC];
self.viewControllers=@[vc1,vc2,vc3,vc4];
self.selectedViewController=vc3;
}
#pragma mark - 自己定义TabBar
- (void) _makeTabBar
{
//1.定制TabBar
UIView * bgView=[[UIView
alloc] initWithFrame:CGRectMake(0,kH-49,kW,49)];
bgView.backgroundColor=[UIColor
whiteColor];
[self.view
addSubview:bgView];
//2.定制button
CGFloat space=(kW-kLeftSpace-kRightSpace-3*kMiddleSpace)/4;
//每一个小button的宽度
for (int i=0; i<4; i++)
{
UITabBarButton * button=[[UITabBarButton
alloc]initWithFrame:CGRectMake(kLeftSpace+i*space+i*kMiddleSpace,
0, space, 49)];
button.backgroundColor=[UIColor
whiteColor];
button.tag=i;
NSString * imageName=[NSString
stringWithFormat:@"%d",i+1];
[button setImage:[UIImage
imageNamed:imageName] forState:UIControlStateNormal];
if (i==2)
{
NSString * imageName=[NSString
stringWithFormat:@"0%d",i+1];
[button setImage:[UIImage
imageNamed:imageName] forState:UIControlStateNormal];
}
[button addTarget:self
action:@selector(changeImage:)
forControlEvents:UIControlEventTouchUpInside];
button.delegateMe=self;
[self.buttonArray
addObject:button];
[bgView
addSubview:button];
}
}
- (void) changeImage:(UITabBarButton *) button
{
for (int i=0; i<4; i++)
{
if (i!=button.tag)
{
NSString * imageName=[NSString
stringWithFormat:@"%d",i+1];
UIButton *butt=self.buttonArray[i];
[butt setImage:[UIImage
imageNamed:imageName] forState:UIControlStateNormal];
}
}
[button.delegateMe
changePage:button.tag];
NSString * imageName=[NSString
stringWithFormat:@"0%d",(int)(button.tag+1)];
[button setImage:[UIImage
imageNamed:imageName] forState:UIControlStateNormal];
}
- (void)changePage:(NSInteger)index
{
[UIView
beginAnimations:nil
context:nil];
[UIView
commitAnimations];
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 {
[super
viewDidLoad];
self.title=@"秒表";
//小时钟
UILabel * conLabel=[[UILabel
alloc]initWithFrame:CGRectMake(267,
85, 110,
50)];
// conLabel.backgroundColor=[UIColor redColor];
conLabel.text=@"00:00.00";
conLabel.font=[UIFont
fontWithName:nil
size:25];
[self.view
addSubview:conLabel];
//秒表
UILabel * ctLabel=[[UILabel
alloc]initWithFrame:CGRectMake(0,160,kW,150)];
// ctLabel.backgroundColor=[UIColor redColor];
ctLabel.text=@"00:00.00";
ctLabel.textAlignment=NSTextAlignmentCenter;
ctLabel.font=[UIFont
fontWithName:nil
size:75];
[self.view
addSubview:ctLabel];
//下方视图
UIView * bView=[[UIView
alloc]initWithFrame:CGRectMake(0,350,kW,300)];
bView.backgroundColor=[UIColor
colorWithRed:0.1
green:0.1
blue:0.1
alpha:0.1];
[self.view
addSubview:bView];
//開始停止button
UIButton * ssButton=[[UIButton
alloc]initWithFrame:CGRectMake((kW-200)/3,
30, 100,
100)];
ssButton.backgroundColor=[UIColor
whiteColor];
ssButton.layer.cornerRadius=50;
[ssButton setTitle:@"開始"
forState:UIControlStateNormal];
[ssButton setTitle:@"停止"
forState:UIControlStateSelected];
[ssButton setTitleColor:[UIColor
redColor] forState:UIControlStateNormal];
[ssButton setTitleColor:[UIColor
grayColor] forState:UIControlStateSelected];
ssButton.tag=1;
[ssButton addTarget:self
action:@selector(StartStop:)
forControlEvents:UIControlEventTouchUpInside];
[bView
addSubview:ssButton];
//计次button
UIButton * jcButton=[[UIButton
alloc]initWithFrame:CGRectMake(((kW-200)/3)*2+100,
30, 100,
100)];
jcButton.backgroundColor=[UIColor
whiteColor];
jcButton.layer.cornerRadius=50;
[jcButton setTitle:@"计次"
forState:UIControlStateNormal];
[jcButton setTitleColor:[UIColor
blackColor] forState:UIControlStateNormal];
[jcButton addTarget:self
action:@selector(CountNum)
forControlEvents:UIControlEventTouchUpInside];
[bView
addSubview:jcButton];
}
- (void)StartStop:(UIButton *) button
{
button.selected = !button.selected;
NSLog(@"%i", button.selected);
NSLog(@"asdasdasd");
}
- (void)CountNum
{
NSLog(@"////////");
}
@end
PS:做一个小项目是最能考验一个人的综合水平,so,自觉水平太low了~ ~ ~ 一定要好好补补课啊!。。( 心碎难补中~)