您的位置:首页 > 产品设计 > UI/UE

UISwitch

2015-06-16 14:28 441 查看
//
//  UISwitchViewController.m
//  AppUI组件学习
//
//  Created by 麦子 on 15/6/16.
//  Copyright (c) 2015年 麦子. All rights reserved.
//

#import "UISwitchViewController.h"

@interface UISwitchViewController ()

@end

@implementation UISwitchViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor];
[self createView:self.view];
}

- (void)createView:(id)uiView{
UIView *view = (UIView *)uiView;
UISwitch *switchView = [[UISwitch alloc] init];
switchView.frame = CGRectMake(20, 80, 300, 100);
//    switchView.backgroundColor = [UIColor redColor];

// 设置开启状态颜色
switchView.onTintColor = [UIColor orangeColor];
// 设置关闭颜色
switchView.tintColor = [UIColor yellowColor];
// 设置圆形按钮颜色
switchView.thumbTintColor = [UIColor purpleColor];

// 设置开启状态图片---(没效果)
switchView.onImage = [UIImage imageNamed:@"tupian2.jpg"];
switchView.offImage = [UIImage imageNamed:@"tupian3.jpg"];

// 设置状态(这个地方的设置,是不会发送事件的,不回触发下面的事件。点击的时候才触发)
[switchView setOn:true animated:true];

[switchView addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged];

[view addSubview:switchView];

}

- (void)switchChange:(UISwitch *)mySwitch{
if (mySwitch.on) {
NSLog(@"开关开启");
}else{
NSLog(@"开关关闭");
}

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UISwitch