星空网 > 软件开发 > 操作系统

iOS开发日记57

今天博主有一个自定义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);

    }];

}

 




原标题:iOS开发日记57

关键词:IOS

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

美国海外仓为什么会成为很多跨境卖家的刚需 :https://www.goluckyvip.com/news/9345.html
卖家别慌!Shopee菲律宾站增收的手续费与你无关! :https://www.goluckyvip.com/news/9346.html
亚马逊代缴vat-可以退税么自己又申报交了一次:https://www.goluckyvip.com/news/9347.html
Shopee、coupang卖家该如何运营?测评自养号解析。 :https://www.goluckyvip.com/news/9348.html
杀疯了,TikTok开启“电话”询盘功能 :https://www.goluckyvip.com/news/9349.html
Shopee 平台创业环境全解析:市场潜力,入驻门槛,热卖品类 :https://www.goluckyvip.com/news/935.html
深度解析:美国公司股东人数限制 :https://www.kjdsnews.com/a/1840835.html
深度解析:美国公司股东人数限制 :https://www.xlkjsw.com/news/88201.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流