【代码笔记】iOS-自定义开关
来源:互联网 发布:淘宝淡季是几月份 编辑:程序博客网 时间:2024/06/05 02:22
一,效果图。
二,工程图。
三,代码。
RootViewController.h
#import <UIKit/UIKit.h>#import "ToggleView.h"@interface RootViewController : UIViewController<ToggleViewDelegate>@property(nonatomic, strong)ToggleView *toggleViewWithLabel;@property(nonatomic, strong)ToggleView *toggleViewWithoutLabel;@property(nonatomic, strong)ToggleView *toggleViewBaseChange;@property(nonatomic, strong)ToggleView *toggleViewButtonChange;@end
RootViewController.m
#import "RootViewController.h"@interface RootViewController ()@end@implementation RootViewController@synthesize toggleViewWithLabel;@synthesize toggleViewWithoutLabel;@synthesize toggleViewBaseChange;@synthesize toggleViewButtonChange;- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //可以通过换图片,而为成自己需要的按钮。 [[self navigationController] setNavigationBarHidden:YES animated:YES]; toggleViewWithLabel = [[ToggleView alloc]initWithFrame:CGRectMake(0, 50, 320, 75) toggleViewType:ToggleViewTypeWithLabel toggleBaseType:ToggleBaseTypeDefault toggleButtonType:ToggleButtonTypeDefault]; toggleViewWithLabel.toggleDelegate = self; toggleViewWithoutLabel = [[ToggleView alloc]initWithFrame:CGRectMake(0, 150, 320, 75) toggleViewType:ToggleViewTypeNoLabel toggleBaseType:ToggleBaseTypeDefault toggleButtonType:ToggleButtonTypeDefault]; toggleViewWithoutLabel.toggleDelegate = self; toggleViewBaseChange = [[ToggleView alloc]initWithFrame:CGRectMake(0, 250, 320, 75) toggleViewType:ToggleViewTypeNoLabel toggleBaseType:ToggleBaseTypeChangeImage toggleButtonType:ToggleButtonTypeDefault]; toggleViewBaseChange.toggleDelegate = self; toggleViewButtonChange = [[ToggleView alloc]initWithFrame:CGRectMake(0, 350, 320, 75) toggleViewType:ToggleViewTypeNoLabel toggleBaseType:ToggleBaseTypeDefault toggleButtonType:ToggleButtonTypeChangeImage]; toggleViewButtonChange.toggleDelegate = self; [self.view addSubview:toggleViewWithLabel]; [self.view addSubview:toggleViewWithoutLabel]; [self.view addSubview:toggleViewBaseChange]; [self.view addSubview:toggleViewButtonChange]; /*label*/ UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(60, 40, 200, 15)]; UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(60, 140, 200, 15)]; UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(60, 240, 200, 15)]; UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(60, 340, 200, 15)]; label1.text = @"Toggle with label."; label2.text = @"Toggle without label."; label3.text = @"Toggle base image change."; label4.text = @"Toggle button image change."; label1.backgroundColor = [UIColor clearColor]; label2.backgroundColor = [UIColor clearColor]; label3.backgroundColor = [UIColor clearColor]; label4.backgroundColor = [UIColor clearColor]; label1.font = [UIFont boldSystemFontOfSize:14]; label2.font = [UIFont boldSystemFontOfSize:14]; label3.font = [UIFont boldSystemFontOfSize:14]; label4.font = [UIFont boldSystemFontOfSize:14]; label1.alpha = 0.7f; label2.alpha = 0.7f; label3.alpha = 0.7f; label4.alpha = 0.7f; label1.textAlignment = 1; label2.textAlignment = 1; label3.textAlignment = 1; label4.textAlignment = 1; [self.view addSubview:label1]; [self.view addSubview:label2]; [self.view addSubview:label3]; [self.view addSubview:label4]; [toggleViewBaseChange setSelectedButton:ToggleButtonSelectedRight]; [toggleViewButtonChange setSelectedButton:ToggleButtonSelectedRight]; }#pragma -mark - ToggleViewDelegate- (void)selectLeftButton{ NSLog(@"LeftButton Selected");}- (void)selectRightButton{ NSLog(@"RightButton Selected");}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
0 0
- 【代码笔记】iOS-自定义开关
- iOS自定义打印开关
- 【代码笔记】iOS-自定义alertView
- 【代码笔记】iOS-自定义switch
- 【代码笔记】iOS-自定义Loading
- IOS自定义view------swtichbutton开关
- 仿IOS开关button 自定义ios开关控件
- android基础笔记——自定义控件和视图:放ios系统开关按钮
- 【代码笔记】iOS-自定义弹出框
- 【代码笔记】iOS-自定义导航条颜色
- 【代码笔记】iOS-自定义选择框
- 【代码笔记】iOS-自定义loading(IanAlert)
- 仿IOS开关自定义View的实现
- 自定义View:仿ios开关按钮控件
- android开发笔记之自定义开关按钮
- 自定义开关
- 自定义开关
- 自定义开关
- 禁用下拉菜单,android5.1源码
- spring—Bean配置
- 画一个折线统计图
- Invoke and BeginInvoke
- linux 调试语句BUG_ON WARN_ON dump_stack panic
- 【代码笔记】iOS-自定义开关
- NOIP 2013 Day1 T3 货车运输
- 单词统计问题
- HttpUrlConnection 和 okhttp 请求数据
- 深入理解Java虚拟机之类加载机制
- 数据结构上机实验之顺序查找
- Git push 报错 fatal: the remote end hung up unexpectedly
- 求Fibonacci数列的第n项
- NOIP 2011 Day1 T2 选择客栈