Ios implements button color conversion and can zoom in, zoom out, and rotate. iosbutton

Source: Internet
Author: User

Ios implements button color conversion and can zoom in, zoom out, and rotate. iosbutton

-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {

_ Window = [[ui1_walloc] initWithFrame: [UIScreenmainScreen]. bounds];

_ Window. backgroundColor = [UIColorwhiteColor];

[_ WindowmakeKeyAndVisible];

// Define a parent View

UIView * superView = [[UIViewalloc] initWithFrame: CGRectMake (65,65, 300,300)];

[_ Window addSubview: superView];

_ Views = [[NSMutableArrayalloc] init];

// Create seven subviews cyclically

For (int I = 0; I <7; I ++ ){

UIView * view = [[UIViewalloc] initWithFrame: CGRectMake (50,50, 250,250)];

// Set the random color

View. backgroundColor = [UIColorcolorWithRed: arc4random () % 10 *. 1 green: arc4random () % 10 *. 1 blue: arc4random () % 10 *. 1 alpha: 1];

[_ Window addSubview: view];

UIView * lastView = [_ viewslastObject];

If (lastView! = Nil ){

View. transform = CGAffineTransformScale (lastView. transform, 0.8, 0.8 );

}

[_ Views addObject: view];

}

// Add several buttons on the interface to implement different functions

UIButton * button1 = [UIButtonbuttonWithType: UIButtonTypeRoundedRect];

[Button1 setTitle: @ "Rotate" forState: UIControlStateNormal];

Button1.tag= 101;

Button1.frame = CGRectMake (50,320, 50, 30 );

[Button1 addTarget: selfaction: @ selector (buttonAction :) forControlEvents: UIControlEventTouchUpInside];

[_ Window addSubview: button1];


UIButton * button2 = [UIButtonbuttonWithType: UIButtonTypeRoundedRect];

[Button2 setTitle: @ "zoom in" forState: UIControlStateNormal];


Button2.tag= 102;

Button2.frame = CGRectMake (150,320, 50, 30 );

[Button2 addTarget: selfaction: @ selector (buttonAction :) forControlEvents: UIControlEventTouchUpInside];

[_ Window addSubview: button2];

UIButton * button3 = [UIButtonbuttonWithType: UIButtonTypeRoundedRect];

[Button3 setTitle: @ "" forState: UIControlStateNormal];

Button3.tag= 103;

Button3.frame = CGRectMake (250,320, 50, 30 );

[Button3 addTarget: selfaction: @ selector (buttonAction :) forControlEvents: UIControlEventTouchUpInside];

[_ Window addSubview: button3];

_ Index = 0;

Return YES;

}


// Button click event

-(Void) buttonAction :( UIButton *) button {

If (button. tag = 103 ){

For (UIView * viewin _ views ){

View. transform = CGAffineTransformScale (view. transform,. 5,. 5 );

}

} Else if (button. tag = 102)

{

For (UIView * viewin _ views ){

View. transform = CGAffineTransformScale (view. transform, 2, 2 );

}

} Else {

// Enable a timer

[NSTimerscheduledTimerWithTimeInterval: 1 target: selfselector: @ selector (timeAction :) userInfo: nilrepeats: YES];

}

}


// Timer

-(Void) timeAction :( NSTimer *) time {

[UIViewbeginAnimations: nilcontext: nil];

[UIViewsetAnimationDuration: 1.9];

For (UIView * viewin _ views ){

View. backgroundColor = [UIColorcolorWithRed: arc4random () % 10 *. 1 green: arc4random () % 10 *. 1 blue: arc4random () % 10 *. 1 alpha: 1];

View. transform = CGAffineTransformRotate (view. transform, M_PI/10 );

}

[UIViewcommitAnimations];

_ Index ++;

If (_ index = 10 ){

For (UIView * viewin _ views ){

[View removeFromSuperview];

}

[Time invalidate];

}

}

The interface opened by the simulator is rotated to zoom in and out

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.