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

先创建一个单视图项目;

//

//  HXViewController.h

//  switchSlider

//

//


#import <UIKit/UIKit.h>


@interface HXViewController : UIViewController

{

    UISwitch *mySwitch;

    IBOutlet UILabel *label1;

    IBOutlet UILabel *label2;

}

@property (retain,nonatomic)IBOutlet UISwitch *mySwitch;

@property (retain,nonatomic)IBOutlet UILabel *label1;

@property (retain,nonatomic)IBOutlet UILabel *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 = [NSString stringWithFormat:@"%f",(((UISlider *)sender).value) * 100];

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

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

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

    {

        [mySwitch setOn:YES animated:YES];

    }

}



- (void)viewDidLoad

{

    [super viewDidLoad];

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

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

- (void)dealloc

{

    [_mySwitch release];

    [_label1 release];

    [_label2 release];

    [super dealloc];

}


@end





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值