//
// ViewController.m
// UISwitch
//
// Created by City--Online on 15/5/19.
// Copyright (c) 2015年 XQB. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong) UISwitch *uiSwitch;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_uiSwitch=[[UISwitch alloc]initWithFrame:CGRectMake(10, 100, 40, 20)];
//设置打开时的TintColor颜色
_uiSwitch.onTintColor=[UIColor redColor];
//设置时的关闭tintColor
_uiSwitch.tintColor=[UIColor blueColor];
//设置滑块的颜色
_uiSwitch.thumbTintColor=[UIColor blackColor];
// _uiSwitch.onImage=[UIImage imageNamed:@"1.jpg"];
// _uiSwitch.offImage=[UIImage imageNamed:@"2.jpg"];
_uiSwitch.on=YES;
[_uiSwitch addTarget:self action:@selector(Onchanged) forControlEvents:UIControlEventValueChanged];
//改变状态
// [_uiSwitch setOn:NO animated:YES];
[self.view addSubview:_uiSwitch];
}
-(void)Onchanged
{
NSLog(@"%d",_uiSwitch.on);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
时间: 2024-12-23 05:41:01