ios开关和滑块控件操作学习

来源:互联网 发布:磁链下载软件 编辑:程序博客网 时间:2024/04/16 23:47

先创建一个单视图项目;

//

//  HXViewController.h

//  switchSlider

//

//


#import <UIKit/UIKit.h>


@interface HXViewController :UIViewController

{

   UISwitch *mySwitch;

   IBOutlet UILabel *label1;

   IBOutlet UILabel *label2;

}

@property (retain,nonatomic)IBOutletUISwitch *mySwitch;

@property (retain,nonatomic)IBOutletUILabel *label1;

@property (retain,nonatomic)IBOutletUILabel *label2;


- (IBAction)handleSwitch:(id)sender;

- (IBAction)handleSlider:(id)sender;


@end





//

//  HXViewController.m

//  switchSlider

//

/

//


#import "HXViewController.h"


@interface HXViewController ()


@end


@implementation HXViewController

@synthesize mySwitch =_mySwitch;

@synthesize label1 =_label1;

@synthesize label2 =_label2;


- (IBAction)handleSwitch:(id)sender

{

   if ([((UISwitch *)sender)isOn] == YES)//开关控件操作

    {

        NSLog(@"it is on!");

    }else

    {

        NSLog(@"it is off!");

    }

}

- (IBAction)handleSlider:(id)sender//滑片控件操作

{

    self.label1.text = [NSStringstringWithFormat:@"%f",(((UISlider *)sender).value) *100];

    self.label2.text = [NSStringstringWithFormat:@"%f",(1 - ((UISlider *)sender).value) * 100];

   NSLog(@"value: %f",((UISlider *)sender).value);

   if ([(UISlider *)sendervalue] == ((UISlider *)sender).maximumValue)

    {

        [mySwitchsetOn:YES animated:YES];

    }

}



- (void)viewDidLoad

{

    [superviewDidLoad];

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

}


- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (void)dealloc

{

    [_mySwitch release];

    [_label1release];

    [_label2release];

    [superdealloc];

}


@end





原创粉丝点击