OSwitch 0.2.0

OSwitch 0.2.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年11月

Oya Said 维护。



OSwitch 0.2.0

  • Oya Said

一个基于 UISwitch 的可定制控件,用 Objective C 编写,灵感来源于 DVSwitch

Animated presentation of the switch

用法

首先导入!

#import "OSwitch/OSwitch.h"

控件可以通过 storyboard/nib 或程序方式添加。

使用 storyboard 添加

  • 在 storyboard/nib 文件中添加一个 UIView
  • Identity Inspector-> 将类名更改为 OSwitch

程序添加

  • 在你的 View Controller 中采用 "OSwitchDelegate" 协议
  • 添加
OSwitch *oSwitch = [[OSwitch alloc] initWithFrame:CGRectMake(0, 300, 300, 40)];
[self.view addSubview:oSwitch];

添加代理

  • 在你的 View Controller .h 中采用 "OSwitchDelegate" 协议
  • 在 View Controller 中设置代理
oSwitch.delegate = self;
  • 在 .m 文件中实现以下方法
- (NSArray *)titlesInSwitch:(OSwitch *)switchView {
    //TODO: return list of titles for the control here
    return titles;
}
- (void)switchView:(OSwitch *)switchView valueDidChangeAtIndex:(NSUInteger)index {
   //TODO: do stuff here
}

自定义

您可以自定义许多内容

  • UIColor *backgroundColor - 控制背景颜色
  • UIColor *sliderColor - 滑块颜色
  • UIColor *textColor - 滑块外的文字颜色
  • UIColor *selectedTextColor - 滑块上的文字颜色
  • CGFloat cornerRadius - 控件和滑块的圆角半径
  • CGFloat offset - 滑块和控制边缘之间的像素偏移量