登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

年、月、日 日期选择器

[复制链接]
来自: cyh142348 分类: iOS精品源码 上传时间: 2016-6-1 15:48:08
Tag:日期选择器 选择器 DatePicker Date Time

项目介绍:

今天和大家分享一下,我自己写的关于日期分别已年、月、日加减的方法,可以切换今天/本月/本季度/本年的不同选择项。


主要代码:
[Objective-C] 查看源文件 复制代码
#import "ViewController.h"
#import "HZDateSelectView.h"
#import "UIView+Extension.h"
#import "UIImage+ChangeColor.h"

@interface ViewController ()

/***  时间加减选择器 */
@property (nonatomic , weak) HZDateSelectView *dateView;

/***  日期切换上一个按钮 */
@property (nonatomic , weak) UIButton *currentBtn;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor lightGrayColor];
    
    UIView *dataSeletedView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, SCREENW, 40)];
    [self.view addSubview:dataSeletedView];
    for (int i = 0; i < 4; i ++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(i * SCREENW / 4 + 10, 10, SCREENW / 4 - 20, 26)];
        [dataSeletedView addSubview:btn];
        btn.tag = i ;
        btn.selected = NO;
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = btn.height * 0.5;
        [btn setBackgroundImage:[UIImage imageWithColor:HZWhiteColor] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageWithColor:HZBlueColor] forState:UIControlStateSelected];
        [btn setTitleColor:HZBlackColor forState:UIControlStateNormal];
        [btn setTitleColor:HZWhiteColor forState:UIControlStateSelected];
        [btn addTarget:self action:@selector(dataBtn:) forControlEvents:UIControlEventTouchUpInside];
        if (btn.tag == 0) {
            self.currentBtn = btn;
            btn.selected = YES;
            [btn setTitle:@"今天" forState:UIControlStateNormal];
        } else if (btn.tag == 1) {
            [btn setTitle:@"本月" forState:UIControlStateNormal];
        } else if (btn.tag == 2) {
            [btn setTitle:@"本季度" forState:UIControlStateNormal];
        } else if (btn.tag == 3) {
            [btn setTitle:@"本年" forState:UIControlStateNormal];
        }
    }
    
    HZDateSelectView *dateView = [[HZDateSelectView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(dataSeletedView.frame), SCREENW, 50)];
    self.dateView = dateView;
    dateView.type = 0;
    [self.view addSubview:dateView];
}

#pragma mark - 时间选择按钮点击
- (void)dataBtn:(UIButton *)button{
    self.currentBtn.selected = NO;
    button.selected = YES;
    self.dateView.type = button.tag;
    [self.dateView layoutSubviews];
    self.currentBtn = button;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end



HZDateChoiceView.zip (89.46 KB, 下载次数: 228)
828 0 0
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542


代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表