• 左右点击--日期增减


    -(UIView *)viewGetByDate

    {

        UIView *view=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 180, 50)];

        //view.backgroundColor=[UIColor redColor];

        UIButton *btnRight=[UIButton buttonWithType:UIButtonTypeCustom];

        btnRight.frame=CGRectMake(view.frame.size.width-30, 10, 20, 20);

        btnRight.tag=160;

        [btnRight setBackgroundImage:[UIImage imageNamed:@"right1"] forState:UIControlStateNormal];

        [btnRight addTarget:self action:@selector(btnDateClick:) forControlEvents:UIControlEventTouchUpInside];

        [view addSubview:btnRight];

        

        UIButton *btnLeft=[UIButton buttonWithType:UIButtonTypeCustom];

        btnLeft.frame=CGRectMake(10, 10, 20, 20);

        btnLeft.tag=161;

        [btnLeft setBackgroundImage:[UIImage imageNamed:@"left1"] forState:UIControlStateNormal];

        [btnLeft addTarget:self action:@selector(btnDateClick:) forControlEvents:UIControlEventTouchUpInside];

        [view addSubview:btnLeft];

        

        _labTime=[[UILabel alloc]initWithFrame:CGRectMake(35, 10, view.frame.size.width-60, 20)];

        _labTime.text=@"2015-12-28";

        _labTime.textAlignment=NSTextAlignmentCenter;

        [view addSubview:_labTime];

        return view;

    }

    -(void)btnDateClick:(UIButton *)sender

    {

        //2012-12-10

        NSInteger year=[[_labTime.text substringWithRange:NSMakeRange(0, 4)] integerValue];

        NSInteger mouth=[[_labTime.text substringWithRange:NSMakeRange(5, 2)] integerValue];

        NSInteger day=[[_labTime.text substringWithRange:NSMakeRange(8, 2)] integerValue];

        if (sender.tag==161)

        {

            if (day>1) {

                day--;

            }

            else

            {

                if (mouth>1) {

                    mouth--;

                    day=[MyTime getDayCountOfMouthAndYear_mouth:mouth year:year];

                }

                else

                {

                    mouth=12;

                    day=[MyTime getDayCountOfMouthAndYear_mouth:mouth year:year];

                    year--;

                }

     

            }

        }

        

        if (sender.tag==160)

        {

            NSInteger count=[MyTime getDayCountOfMouthAndYear_mouth:mouth year:year];

            if (day<count) {

                day++;

                

            }

            else

            {

                if (mouth<12) {

                    mouth++;

                    day=1;

                }

                else

                {

                    mouth=1;

                    day=1;

                    year++;

                }

                

            }

        }

        NSString *d=[NSString stringWithFormat:@"%d",day];

        NSString *y=[NSString stringWithFormat:@"%d",year];

        NSString *m=[NSString stringWithFormat:@"%d",mouth];

        if (day<10) {

            d=[NSString stringWithFormat:@"0%d",day];;

        }

        if (mouth<10) {

            m=[NSString stringWithFormat:@"0%d",mouth];;

        }

        if (year<1000) {

            y=[NSString stringWithFormat:@"0%d",year];;

        }

        _labTime.text=[NSString stringWithFormat:@"%@-%@-%@",y,m,d];

    }

  • 相关阅读:
    ElasticSearch : APT-GET安装方式
    python__基础 : 多继承中方法的调用顺序 __mro__方法
    TypeScript : 语法及特性
    Spring : JDBC模板, 事务和测试
    数据库 : 事物以及隔离性导致的问题
    MySQL数据库 : 函数和存储过程
    Java : java基础(6) 反射与枚举
    Java : java基础(5) Socket网络编程
    Java : java基础(4) 线程
    Java : java基础(3) IO流
  • 原文地址:https://www.cnblogs.com/lvchenhao/p/4451746.html
Copyright © 2020-2023  润新知