Yini  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
STSegmentedControl.h
Go to the documentation of this file.
1 //
2 // STSegmentedControl.h
3 // STSegmentedControl
4 //
5 /*
6 The MIT License
7 
8 Copyright (c) 2011 Cedric Vandendriessche
9 
10 Permission is hereby granted, free of charge, to any person obtaining a copy
11 of this software and associated documentation files (the "Software"), to deal
12 in the Software without restriction, including without limitation the rights
13 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 copies of the Software, and to permit persons to whom the Software is
15 furnished to do so, subject to the following conditions:
16 
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19 
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 THE SOFTWARE.
27  */
28 
29 #import <Foundation/Foundation.h>
30 
31 #define STSegmentedControlHeight 43.0
32 
33 enum {
34  STSegmentedControlNoSegment = -1 // segment index for no selected segment
35 };
36 
37 @interface STSegmentedControl : UIControl {
38  NSMutableArray *segments;
39  UIImage *normalImageLeft;
41  UIImage *normalImageRight;
45  NSUInteger numberOfSegments;
48  BOOL momentary;
49 }
50 
51 - (id)initWithItems:(NSArray *)items; // items can be NSStrings or UIImages.
52 
53 - (void)insertSegmentWithTitle:(NSString *)title atIndex:(NSUInteger)index; // insert before segment number
54 - (void)insertSegmentWithImage:(NSString *)image atIndex:(NSUInteger)index;
55 - (void)removeSegmentAtIndex:(NSUInteger)index;
56 - (void)removeAllSegments;
57 
58 - (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)index;
59 - (NSString *)titleForSegmentAtIndex:(NSUInteger)index;
60 
61 - (void)setImage:(NSString *)image forSegmentAtIndex:(NSUInteger)index;
62 - (UIImage *)imageForSegmentAtIndex:(NSUInteger)index;
63 
64 @property (nonatomic) NSMutableArray *segments; // at least two (2) NSStrings are needed for a STSegmentedControl to be displayed
65 @property (nonatomic) UIImage *normalImageLeft;
66 @property (nonatomic) UIImage *normalImageMiddle;
67 @property (nonatomic) UIImage *normalImageRight;
68 @property (nonatomic) UIImage *selectedImageLeft;
69 @property (nonatomic) UIImage *selectedImageMiddle;
70 @property (nonatomic) UIImage *selectedImageRight;
71 @property (nonatomic, readonly) NSUInteger numberOfSegments;
72 @property (nonatomic, getter=isMomentary) BOOL momentary; // if set, then we don't keep showing selected state after tracking ends. default is NO
73 
74 // returns last segment pressed. default is STSegmentedControlNoSegment until a segment is pressed. Becomes STSegmentedControlNoSegment again when altering the amount of segments
75 // the UIControlEventValueChanged action is invoked when the segment changes via a user event. Set to UISegmentedControlNoSegment to turn off selection
76 @property (nonatomic, readwrite) NSInteger selectedSegmentIndex;
77 
78 -(void)initializeImages;
79 
80 @end