你的位置:首页 > 软件开发 > 操作系统 > iOS开发日记57

iOS开发日记57

发布时间:2015-12-29 18:00:04
今天博主有一个自定义SegmentControl的需求,遇到了一些困难点,在此和大家分享,希望能够共同进步.先来看看效果图利用视觉差实现的效果,代码并不难,贴出来请各位看官自行研究- (void)viewDidLoad { [super viewDidLoad]; ...

今天博主有一个自定义SegmentControl的需求,遇到了一些困难点,在此和大家分享,希望能够共同进步.

先来看看效果图

利用视觉差实现的效果,代码并不难,贴出来请各位看官自行研究

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    NSArray *array=[NSArray arrayWithObjects:@"Apple",@"Hello",@"Swift",@"World", nil];

    for (int i=0; i<4; i++) {

        UILabel *blackLabel=[[UILabel alloc]initWithFrame:CGRectMake(50+i*70, 300, 70, 30)];

        blackLabel.text=array[i];

        blackLabel.textAlignment=NSTextAlignmentCenter;

        blackLabel.textColor=[UIColor blackColor];

        [self.view addSubview:blackLabel];

    }

    self.redView=[[UIView alloc]initWithFrame:CGRectMake(50, 300, 70, 30)];

    _redView.clipsToBounds=YES;

    _redView.backgroundColor=[UIColor redColor];

    _redView.layer.cornerRadius=15.0;

    [self.view addSubview:_redView];

    self.whiteView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 70, 30)];

    [_redView addSubview:_whiteView];

    for (int i=0; i<4; i++) {

        UILabel *dLabel=[[UILabel alloc]initWithFrame:CGRectMake(i*70, 0, 70, 30)];

        dLabel.text=array[i];

        dLabel.textAlignment=NSTextAlignmentCenter;

        dLabel.textColor=[UIColor whiteColor];

        [_whiteView addSubview:dLabel];

    }

    for (int i=0; i<4; i++) {

        UIButton *buttonOF=[UIButton buttonWithType:UIButtonTypeCustom];

        buttonOF.backgroundColor=[UIColor clearColor];

        buttonOF.adjustsImageWhenHighlighted=NO;

        buttonOF.tag=1000+i;

        buttonOF.frame=CGRectMake(50+i*70, 300, 70, 30);

        [buttonOF addTarget:self action:@selector(moveToNew:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:buttonOF];

    }

}

 

-(void)moveToNew:(UIButton *)button

{

    [UIView animateWithDuration:5 animations:^{

        _redView.frame=CGRectMake(50+(button.tag-1000)*70, 300, 70, 30);

        _whiteView.frame=CGRectMake(-(button.tag-1000)*70, 0, 70, 30);

    }];

}

 


 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:iOS开发日记57

关键词:IOS

IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。