JFADoubleSlider 1.0.0

JFADoubleSlider 1.0.0

测试已测试
语言语言 Objective-CObjective C
许可证 MIT
发布日期最新发布2015年9月

Josh Adams维护。



UISlider是一个方便的控制图标选择值,但是苹果没有提供选择范围的控件。存在许多开源控件可选择范围值,但它们必须在代码中实例化和操作,而不是使用Interface Builder。JFADoubleSliderUISlider启发,允许用户选择一个范围值,可以是整数或非整数。开发者可以在代码中实例化和操作JFADoubleSlider,也可以使用Xcode的新IBDesignable/IBInspectable功能,通过Interface Builder进行操作。

演示

要演示JFADoubleSlider,克隆仓库,双击JFADoubleSlider.xcodeproj,然后在设备或模拟器上运行。此演示显示了使用JFADoubleSlider的代码和Interface Builder技术。这里是演示的视频:[https://vimeo.com/117676693](https://vimeo.com/117676693)

使用

以下是使用JFADoubleSlider的步骤。

  1. JFADoubleSlider.hJFADoubleSlider.m添加到您的项目中。

  2. 在您的视图控制器的.m文件中引入JFADoubleSlider.h

  3. 决定您是想以代码的方式实例化和操作JFADoubleSlider,还是通过Interface Builder。如果是代码方式,请将以下代码放到您的视图控制器的viewDidLoad:方法中。您必须指定自动布局约束。下面的代码,来自示范应用程序,实例化滑块,设置一些属性,实例化并设置标签,并将JFADoubleSlider和标签固定到视图的底部。

    JFADoubleSlider *programmaticSlider = [[JFADoubleSlider alloc] initWithFrame:self.view.frame];
    programmaticSlider.delegate = self;
    programmaticSlider.absMinVal = -5000.0;
    programmaticSlider.absMaxVal = 5000.0;
    programmaticSlider.curMinVal = -1420.0;
    programmaticSlider.curMaxVal = 1420.0;
    programmaticSlider.reportInteger = YES;
    [self.view addSubview:programmaticSlider];
    UILabel *label = [UILabel new];
    label.translatesAutoresizingMaskIntoConstraints = NO;
    label.text = @"Programmatic Double Slider";
    label.font = [UIFont systemFontOfSize:22];
    [label sizeToFit];
    [self.view addSubview:label];
    NSDictionary *viewDict = @{@"slider":programmaticSlider, @"label":label};
    NSArray *vertConstr = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[label][slider]-|" options:0 metrics:nil views:viewDict];
    [self.view addConstraints:vertConstr];
    NSArray *horizConstr = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[slider]-|" options:0 metrics:nil views:viewDict];
    [self.view addConstraints:horizConstr];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0.0]];

如果想要使用Interface Builder,将UIView拖入您的视图中;设置高度为62点,宽度为您想要的宽度;将视图的类设置为JFADoubleSlider;添加适当的约束;并通过使用工具栏中属性检查器的UI部分,设置任何不想使用默认值的属性。如果希望在视图中访问JFADoubleSlider,请在视图控制器中实现,从JFADoubleSlider创建一个出口到视图控制器,设置它的代表,并实现JFADoubleSliderDelegate的相关回调方法。以下视频显示了所有这些步骤,但到最后一步没有提及:[https://vimeo.com/117679785](https://vimeo.com/117679785)

开发者对在Interface Builder中手动将JFADoubleSlider的高度设置为62点表示遗憾,但似乎没有一种方法可以通过使用,例如,固有内容大小来自动设置IBDesignable/IBInspectable控件的大小。相比之下,UISlider(例如),拖入视图后就拥有适当的高度。实际上,在Interface Builder中无法修改UISlider的高度。

有关JFADoubleSlider的属性和控制协议JFASliderDelegate的描述,请参阅JFADoubleSlider.h中的注释。

创建者

Josh Adams

贡献者

感谢Jack Cox对他的教程关于IBDesignable/IBInspectable的帮助。

感谢PJ Vea对代码的审查。

许可

The MIT License (MIT)

Copyright (c) 2015 Josh Adams

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.