IOS development diary 57-gradient effect SegmentControl, 57-segmentcontrol

Source: Internet
Author: User

IOS development diary 57-gradient effect SegmentControl, 57-segmentcontrol

Today, the blogger has a demand for custom SegmentControl and has encountered some difficulties. I would like to share with you the hope to make common progress.

Let's take a look at it. When the speed is slow, we will find that when the red view moves, the colors of the two sides of the Label are different.

The code is not difficult to achieve with poor visual effects. Post the code and ask the readers to study it on their own.

-(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];

_ Red view. 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 );

}];

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.