IOS Ui-button button

Source: Internet
Author: User

1 #import "ViewController.h"2 3 @interfaceViewcontroller ()4 {5UILabel *lable;6 BOOL Moveflag;7 nsinteger length;8UIButton *btn;9Nstimer *timer;Ten } One  A @end -  - @implementationViewcontroller the  -- (void) Viewdidload { - [Super Viewdidload]; -Moveflag =NO; +Length =Ten; -      +Self.view.backgroundColor =[Uicolor Darkgraycolor]; Alable =[[UILabel alloc] init]; atLable.frame = CGRectMake ( -, -,280, -); -Lable.text =@"dot me."; -Lable.backgroundcolor =[Uicolor Whitecolor]; - [Self.view addsubview:lable]; -      -     //button UIButton inBTN =[UIButton Buttonwithtype:uibuttontypecustom]; -     //Set button coordinates, size toBtn.frame = CGRectMake ( the, -, -, -); +     //Setting the background map -[Btn setimage:[uiimage imagenamed:@"Fire_down.png"] forstate:uicontrolstatenormal]; the[Btn setimage:[uiimage imagenamed:@"Blue_down.png"] forstate:uicontrolstatehighlighted]; *  $     Panax Notoginseng     //Set caption (status title) - //[btn settitle:@ "Start" forstate:uicontrolstatenormal]; the //[btn settitle:@ "Press" forstate:uicontrolstatehighlighted]; +      A     //add an [associated event] to a button the [btn addtarget:self Action: @selector (Touchme) forcontrolevents:uicontroleventtouchupinside]; +     //Add a background color - [btn Setbackgroundcolor:[uicolor cyancolor]; $      $     //Button turns round -Btn.layer.cornerRadius = -; -     //Add a button to the view the [Self.view addsubview:btn]; - Wuyi } the  --(void) Touchme Wu { -     //The ball didn't move when I judged it. About     if(Moveflag = =NO) { $Moveflag =YES; -     } -     Else -Moveflag =NO; A      +     //when the ball is not moving, point the ball-change the     if(moveflag) { -Timer = [Nstimer timerwithtimeinterval:0.1target:self selector: @selector (bollmove) Userinfo:nil Repeats:yes]; $ [[Nsrunloop Currentrunloop] Addtimer:timer formode:nsrunloopcommonmodes]; the     } the     Else the [timer invalidate]; the     //when the ball moves, point the ball-don't move . -      in } the  the-(void) Bollmove About { the      the     if(btn.frame.origin.y> -) { theLength =-Ten; +  -     } the     Else if(btn.frame.origin.y<0)Bayi     { theLength =Ten; the     } -      -CGRect rect =Btn.frame; theRECT.ORIGIN.Y + =length; theBtn.frame =rect; the  the}

IOS Ui-button button

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.