[翻译] TWRPickerSlider
TWRPickerSlider
https://github.com/chasseurmic/TWRPickerSlider
Usage
Add the dependency to your?Podfile:
用 Podfile 添加依賴關系
platform :bios pod 'TWRPickerSlider’, ‘~> 1.0’ ...Run?pod install?to install the dependencies.
運行 pod install 來安裝依賴
Next, import the header file wherever you want to use the picker:
下一步,導入頭文件
#import "TWRSliderStackedView.h" #import "TWRPickerSlider.h"You should first initialize your?TWRPickerSlider?as such:
你需要用以下的方式來初始化對象:
TWRPickerSlider *slider1 = [[TWRPickerSlider alloc] init];…and assign some objects for the picker:
然后,你可以給 picker 賦值幾個對象:
slider1.pickerObjects = @[obj1, obj2, obj3];Objects passed to the picker can be of any type, provided they conform to the?TWRPickerSliderDatasource?protocol. Said protocol only requires the user to implement the following method, which returns the string that the picker will display for the object:
對象可以是任意類型,你只需要給TWRPickerSliderDatasource提供字符串數據即可:
- (NSString *)twr_pickerTitle;Then set the picker delegate to be your view controller and implement theTWRPickerSliderDelegate?protocol:
然后設置代理到你的控制器中,并實現協議:
// Set Delegate slider1.delegate = self; // TWRPickerSliderDelegate - (void)objectSelected:(id<TWRPickerSliderDatasource>)selectedObject sender:(TWRPickerSlider *)sender{ NSLog(@"Selected object: %@", [selectedObject twr_pickerTitle]); }Finally add you?TWRPickerSlider?instance to your view. It will automatically position itself at the bottom of the view and animate / slide when pressed.
最后添加?TWRPickerSlider 到你的view上,它會自動的將它自己添加到底端
?
Stacking pickers
Alternatively, if you have or want to display more than one picker at a time, you can instantiate a?TWRSliderStackedView?object and assign it an array of?TWRPickerSlider.
另外,如果你想在同一時間顯示超過一個的picker,你可以初始化TWRSliderStackedView對象,然后在它的數組對象中賦值TWRPickerSlider對象。
TWRSliderStackedView *stack = [[TWRSliderStackedView alloc] init]; stack.sliders = @[slider1, slider2, slider3]; [self.view addSubview:stack];Again, the stacked view will position itself at the bottom of the current view. If you’re working inside a tab bar controller, or if you don’t want the stacked view to stick at the bottom of the view controller, you can use one of the following two methods:
這個?stacked view將會把它自己安置在當前view的底部,如果你是在Tab bar控制器中作業,或者說你不想讓stacked view在這個控制器的底端,你可以用下面的方法來設置:
- (instancetype)initWithBottomPadding:(NSUInteger)padding; - (instancetype)initWithTabBar;See the demo project for more details.
你可以看demo了解更多。
Requirements
TWRPickerSlider?requires iOS 7.x or greater.
TWRPickerSlider需要iOS7.x以上版本
?
總結
以上是生活随笔為你收集整理的[翻译] TWRPickerSlider的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 详解HaProxy
- 下一篇: eclipse 直接去手机中拖文件