Skip to content

Commit

Permalink
Merge pull request #9 from nicolasgoutaland/master
Browse files Browse the repository at this point in the history
UIAppearance support, IB Live rendering and bug fixes
  • Loading branch information
ShadyElyaski committed May 5, 2015
2 parents 9f232c4 + 768084f commit f327bb8
Show file tree
Hide file tree
Showing 36 changed files with 1,601 additions and 9,670 deletions.
Binary file added Assets/sample.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 56 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,79 +5,96 @@ An iOS Filter UIControl Subclass. Zero Graphics. Highly Customizable.

Inspired by National Geographics: Park Guides.

# Installation

1. In your XCode Project, take the *SEFilterControl.h and .m* & *SEFilterKnob.h and .m* from ios-filter-control folder and drag them into your project.
2. Start using this new UIControl Subclass!

# SDK Support

It supports iOS 4 to iOS 6

# Screenshot

Here's a screenshot for different variations

![ScreenShot](https://raw.github.com/nicolasgoutaland/ios-filter-control/master/Assets/sample.gif)

![My image](http://blog.elyaski.com/wp-content/uploads/2012/06/iOS-Simulator-Screen-shot-Jun-16-2012-2.38.16-AM.png)

You may watch a demo video on [Youtube](http://www.youtube.com/watch?v=-lvvLnKPUk8)

# Documentation
# Installation

__Cocoapods:__ pod 'SEFilterControl'

__Manual__:

The class is not very well documented. I tried documenting drawing code as much as I could.
1. In your XCode Project, take the *SEFilterControl.h and .m* & *SEFilterKnob.h and .m* from ios-filter-control folder and drag them into your project.

2. Start using this new UIControl Subclass!

There are sample codes that illustrate various parameters.
# SDK Support

It supports iOS 5 to iOS 8
Live rendering in Interface builder will require Xcode 6.x

# Usage

## Creating your filter

### By Code
Somewhere, for example in your viewDidLoad, alloc and init the filter UIControl:

SEFilterControl *filter = [[SEFilterControl alloc]initWithFrame:CGRectMake(10, 20, 300, 70) Titles:[NSArray arrayWithObjects:@"Articles", @"News", @"Updates", @"Featured", @"Newest", @"Oldest", nil]];
```
SEFilterControl *filter = [[SEFilterControl alloc]initWithFrame:CGRectMake(10, 20, 300, 70) Titles:[NSArray arrayWithObjects:@"Articles", @"News", @"Updates", @"Featured", @"Newest", @"Oldest", nil]];
```

This initializes our Filter Control using CGRect and Titles Array of NSStrings.

*Note That height of the control is predifined as 70 and can't be changed*
*Note That height of the control is predefined as 70 and can't be changed* Use __SEFilterControl_HEIGHT__ const for reference.

Then, add target for Value Change Event handling:

[filter addTarget:self action:@selector(filterValueChanged:) forControlEvents:UIControlEventValueChanged];

Don't forget to impelment the handler we specified later:

-(void)filterValueChanged:(SEFilterControl *) sender{
NSLog(@"%@", [NSString stringWithFormat:@"%d", sender.SelectedIndex]);
}
```
[filter addTarget:self action:@selector(filterValueChanged:) forControlEvents:UIControlEventValueChanged];
```
Don't forget to implement the handler we specified later:

```
-(void)filterValueChanged:(SEFilterControl *) sender{
NSLog(@"%@", [NSString stringWithFormat:@"%d", sender.SelectedIndex]);
}
```

Adding to your UIView & releasing the object:
Adding to your UIView:

```
[self.view addSubview:filter];
[filter release];

## Customizing your filter

To change the track color:
```

[filter setProgressColor:[UIColor lightGrayColor]];
### Via Interface builder
Add a new UIView to your xib, and update its class to __SEFilterControl__.
Bind a UIAction to the __valueChanged__ event of your control.
Enjoy ;)

To change the handler color:
## Configuration
### Filter
| Property | Effect | Default value |
|:-------------:|-------------|-----|-----|
| **progressColor** | Progress track color | SEFilterControl_DEFAULT_PROGRESS_COLOR |
| **titlesFont** | Configure all titles font | SEFilterControl_DEFAULT_TITLE_FONT |
| **titlesColor** | Configure all titles color | SEFilterControl_DEFAULT_TITLE_COLOR |
| **titlesShadowColor** | Configure all titles shadow color | SEFilterControl_DEFAULT_TITLE_SHADOW_COLOR |

[filter setHandlerColor:[UIColor darkGrayColor]];
### Knob
| Property | Effect | Default value |
|:-------------:|-------------| -----|---|
| **handlerColor** | Configure knob color | SEFilterKnob_DEFAULT_HANDLER_COLOR |
| **shadowColor** | Configure knob shadow color | SEFilterKnob_DEFAULT_SHADOW_COLOR |
| **shadow** | Enable / sisable shadow | SEFilterKnob_DEFAULT_SHADOW |

To change the Titles text color:
### Continuous mode
If __continuous__ is set to YES, filter will generate __valueChanged__ events will user is dragging the knb. If NO, an event will be sent once knob released.

[filter setTitlesColor:[UIColor blackColor]];

To change the Titles text font:

[filter setTitlesFont:[UIFont fontWithName:@"Didot" size:14]];

### UIAppearance
__SEFilterControl__ and __SEFilterKnob__ declare __UIAppearance__ methods, allowing you to style all instances at a time.

# Acknowledgment

Special thanks to mash, Ltd. team for their support.

Thanks to Nicolas Goutaland for the updated version.

License
-------
Expand Down
53 changes: 41 additions & 12 deletions SEFilterControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,49 @@
//
// 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.


#import <UIKit/UIKit.h>
#import "SEFilterKnob.h"

@interface SEFilterControl : UIControl{
#define SEFilterControl_HEIGHT 70

#define SEFilterControl_DEFAULT_TITLE_FONT [UIFont fontWithName:@"Optima" size:14]
#define SEFilterControl_DEFAULT_TITLE_SHADOW_COLOR [UIColor lightGrayColor]
#define SEFilterControl_DEFAULT_TITLE_COLOR [UIColor blackColor]
#define SEFilterControl_DEFAULT_PROGRESS_COLOR [UIColor colorWithRed:103/255.f green:173/255.f blue:202/255.f alpha:1]

IB_DESIGNABLE
@interface SEFilterControl : UIControl

/* Default constructor */
- (id) initWithFrame:(CGRect)frame titles:(NSArray *)titles;

/* Constructor with preconfigured labels */
- (id) initWithFrame:(CGRect)frame titles:(NSArray *)titles labels:(NSArray *)labels;

/* Update titles data */
- (void) setTitles:(NSArray *)titles;

/* Update titles data, providing labels to use */
- (void) setTitles:(NSArray *)titles labels:(NSArray *)labels;

/* Set selected index, animated or not */
- (void) setSelectedIndex:(NSUInteger)index animated:(BOOL) animated;

@property (nonatomic, strong) UIFont *titlesFont UI_APPEARANCE_SELECTOR; // Update all titles font
@property (nonatomic, strong) UIColor *titlesColor UI_APPEARANCE_SELECTOR; // Update all titles color
@property (nonatomic, strong) UIColor *titlesShadowColor UI_APPEARANCE_SELECTOR; // Update all titles shadow color
@property (nonatomic, strong, readonly) NSArray *labels; // All titltes array, for a per title customization
@property (nonatomic, readonly) NSUInteger selectedIndex; // Not animated by default
@property (nonatomic, weak, readonly) SEFilterKnob *handler; // Knob
@property (nonatomic, assign) IBInspectable BOOL continuous; // If YES, slider will send updates its times selected index is updated, without waiting for a touch Up. Default is NO
@property (nonatomic, retain) IBInspectable UIColor *progressColor UI_APPEARANCE_SELECTOR; // Progress color

// Old methods
/*! @abstract Use initWithFrame:titles: instead */
- (id) initWithFrame:(CGRect)frame Titles:(NSArray *) titles NS_UNAVAILABLE;

}
-(id) initWithFrame:(CGRect) frame Titles:(NSArray *) titles;
-(id) initWithFrame:(CGRect) frame Titles:(NSArray *) titles Labels:(NSArray *) labels;
-(void) setSelectedIndex:(int)index;
-(void) setTitlesColor:(UIColor *)color;
-(void) setTitlesFont:(UIFont *)font;
-(void) setHandlerColor:(UIColor *)color;
/*! @abstract Use initWithFrame:titles:labels: instead */
- (id) initWithFrame:(CGRect)frame Titles:(NSArray *) titles Labels:(NSArray *) labels NS_UNAVAILABLE;

@property(nonatomic, retain) UIColor *progressColor;
@property(nonatomic, readonly) int SelectedIndex;
/*! @abstract Use selectedIndex */
@property (nonatomic, readonly) NSInteger SelectedIndex NS_UNAVAILABLE;
@end
Loading

0 comments on commit f327bb8

Please sign in to comment.