iOS 时钟分选择器
来源:互联网 发布:mc建筑装饰 知乎 编辑:程序博客网 时间:2024/05/16 09:19
#import "UIView+WZP_frame.h"
#import <UIKit/UIKit.h>
@protocol PickDelegate <NSObject>
@optional
-(void)selectHour:(NSInteger)ho mintue:(NSInteger)min btnTag:(NSUInteger)tag;
@end
@interface HourAndMin : UIView
@property (nonatomic,strong)UILabel *selectTime;
@property (nonatomic,strong)id<PickDelegate>delegate;
#import "HourAndMin.h"
@interface HourAndMin ()<UIPickerViewDelegate,UIPickerViewDataSource>
{
NSInteger hourIndex;
NSInteger minIndex;
}
@property(nonatomic,strong)NSMutableArray *proTimeList;
@property(nonatomic,strong)NSMutableArray *proTitleList;
@property(nonatomic,strong)UILabel *hourLabel;
@property(nonatomic,strong)UILabel *minLabel;
@end
@implementation HourAndMin
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [superinitWithFrame:frame]) {
_selectTime.text=@"00:00";
_proTimeList=[NSMutableArrayarray];
_proTitleList=[NSMutableArrayarray];
[selfaddPickView];
}
returnself;
}
-(void)addPickView{
UIButton *btn0=[[UIButtonalloc]initWithFrame:CGRectMake(0,self.wzp_height*0.4,60, 40)]
;
btn0.tag=0;
[btn0 setTitle:@"取消"forState:UIControlStateNormal];
[btn0 setTitleColor:[UIColorredColor] forState:UIControlStateNormal];
[btn0 setTitleColor:[UIColorblackColor] forState:UIControlStateHighlighted];
[btn0 addTarget:selfaction:@selector(click:)forControlEvents:UIControlEventTouchUpInside];
UIButton *btn1=[[UIButtonalloc]initWithFrame:CGRectMake(self.wzp_width-60,self.wzp_height*0.4,60, 40)]
;
btn1.tag=1;
[btn1 setTitle:@"确认"forState:UIControlStateNormal];
[btn1 setTitleColor:[UIColorredColor] forState:UIControlStateNormal];
[btn1 setTitleColor:[UIColorblackColor] forState:UIControlStateHighlighted];
[btn1 addTarget:selfaction:@selector(click:)forControlEvents:UIControlEventTouchUpInside];
UIPickerView *pickerView = [[UIPickerViewalloc] init];
self.frame=self.bounds;
// 显示选中框
pickerView.showsSelectionIndicator=YES;
pickerView.dataSource =self;
pickerView.delegate =self;
[selfaddSubview:pickerView];
[selfaddSubview:btn0];
[selfaddSubview:btn1];
for (int i=0; i<60; i++) {
NSString *str=[NSStringstringWithFormat:@"%02d分",i];
[_proTimeListaddObject:str];
}
for (int i=0; i<24; i++) {
NSString *str=[NSStringstringWithFormat:@"%02d时",i];
[_proTitleListaddObject:str];
}
}
-(void)click:(UIButton*)btn{
if ([_delegaterespondsToSelector:@selector(selectHour:mintue:btnTag:)]) {
NSLog(@"index---%02ld",hourIndex);
NSLog(@"index---%02ld",minIndex);
[_delegateselectHour:hourIndexmintue:minIndexbtnTag:btn.tag];
}
}
#pragma Mark -- UIPickerViewDataSource
// pickerView 列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return2;
}
// pickerView 每列个数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (component ==0) {
return [_proTitleListcount];
}
return [_proTimeListcount];
}
#pragma Mark -- UIPickerViewDelegate
// 每列宽度
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
if (component ==1) {
return80;
}
return180;
}
// 返回选中的行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component ==0) {
hourIndex=row;
} else {
minIndex=row;
}
}
//返回当前行的内容,此处是将数组中数值添加到滚动的那个显示栏上
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component ==0) {
return [_proTitleListobjectAtIndex:row];
} else {
return [_proTimeListobjectAtIndex:row];
}
}
#import "ViewController.h"
#import "HourAndMin.h"
#import "UIView+WZP_frame.h"
@interface ViewController ()<PickDelegate>
{
HourAndMin *hour;
}
@property (weak,nonatomic) IBOutletUILabel *timeLabel;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
[selfaddhourAndMin];
}
-(void)addhourAndMin{
hour=[[HourAndMinalloc]initWithFrame:CGRectMake(0,0, [UIScreenmainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height*0.4)];
hour.delegate=self;
hour.center=self.view.center;
[self.viewaddSubview:hour];
}
#pragma mark PickDelegate
-(void)selectHour:(NSInteger)ho mintue:(NSInteger)min btnTag:(NSUInteger)tag{
if (tag==0) {
[hourremoveFromSuperview];
}else{
self.timeLabel.text=[NSStringstringWithFormat:@"%02ld:%02ld",ho,min];
[hourremoveFromSuperview];
}
}
- (IBAction)add:(id)sender {
[selfaddhourAndMin];
}
- iOS 时钟分选择器
- 时钟选择器
- 一个模拟时钟的时间选择器 ClockPicker
- ClockPicker – 时钟风格 Bootstrap 时间选择器
- iOS时钟动画实现
- iOS 动画-时钟
- FPGAtestbench中如何产生差分时钟
- IOS选择器的使用
- iOS 时间选择器
- iOS添加日期选择器
- IOS 学习 日期选择器
- iOS开发-------选择器(UIPickView)
- iOS相机选择器
- IOS 图片选择器
- 仿ios日期选择器
- iOS - 颜色选择器
- iOS 自定义日期选择器
- iOS-自定义键盘选择器
- 2017上海国际工业自动化及机器人展览会
- ROM系统定制
- VR技术的威力有多大?业界大佬们是这样说的...
- Redis Cluster原理 - emailed
- 全球福利最好的国家是如何生活的?
- iOS 时钟分选择器
- PullToRefresh实现上拉加载下拉刷新
- printf("%d,%d\n", *ptr, *(ptr++))
- VBA:设定区域显示或者隐藏,显示的单元格自动设定行高
- 银行家算法避免死锁C/C++
- Qt网络编程遇到无法解析的外部命令解决办法
- andorid系统的定制
- Android开发中常用的工具类
- 绕TX驱动保护TesSafe.sys方法