码迷,mamicode.com
首页 > 其他好文 > 详细

第三章 控件使用

时间:2015-05-18 20:30:18      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UISwitch *leftswitch;
@property (weak, nonatomic) IBOutlet UISwitch *rightswitch;
@property (weak, nonatomic) IBOutlet UILabel *label;
- (IBAction)switchvaluechange:(id)sender;
- (IBAction)slidervalue:(UISlider *)sender;
- (IBAction)senderon:(id)sender;

@end
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (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.
}
//3 分段控制
- (IBAction)switchvaluechange:(id)sender {
    if(self.leftswitch.hidden ==YES)
    {
        self.rightswitch.hidden=NO;
        self.leftswitch.hidden=NO;
    }else{
        self.leftswitch.hidden=YES;
        self.rightswitch.hidden=YES;
    
    }
}
//2 滑块控件设置 使用slider控件控制lable控件。
- (IBAction)slidervalue:(UISlider *)sender {
//        _label.text=[NSString stringWithFormat:@"%.f",sender.value];
    //转化为字符串格式
    int progressAsint = (int)(sender.value);
    NSString *newText = [[NSString alloc]initWithFormat:@"%d",progressAsint];
    _label.text=newText;
    
}

//1 使两个按钮能够同步
- (IBAction)senderon:(id)sender
{
    UISwitch *witchSwitch=(UISwitch *)sender;
    BOOL setting = witchSwitch.isOn;
    [self.leftswitch setOn:setting animated:YES];
    [self.rightswitch setOn:setting animated:YES];
}
@end

 

第三章 控件使用

标签:

原文地址:http://www.cnblogs.com/lizhan1991/p/4512733.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!