|
| 1 | +// |
| 2 | +// TOSegmentedControlItem.h |
| 3 | +// |
| 4 | +// Copyright 2019 Timothy Oliver. All rights reserved. |
| 5 | +// |
| 6 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +// of this software and associated documentation files (the "Software"), to |
| 8 | +// deal in the Software without restriction, including without limitation the |
| 9 | +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | +// sell copies of the Software, and to permit persons to whom the Software is |
| 11 | +// furnished to do so, subject to the following conditions: |
| 12 | +// |
| 13 | +// The above copyright notice and this permission notice shall be included in |
| 14 | +// all copies or substantial portions of the Software. |
| 15 | +// |
| 16 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 | +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 20 | +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR |
| 21 | +// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | + |
| 23 | +#import <Foundation/Foundation.h> |
| 24 | + |
| 25 | +@class UIColor; |
| 26 | +@class UIView; |
| 27 | +@class UIImage; |
| 28 | +@class UIImageView; |
| 29 | +@class UILabel; |
| 30 | +@class TOSegmentedControl; |
| 31 | + |
| 32 | +NS_ASSUME_NONNULL_BEGIN |
| 33 | + |
| 34 | +/** |
| 35 | + A private model object that holds all of the |
| 36 | + information and state for a single item in the |
| 37 | + segmented control. |
| 38 | + */ |
| 39 | +@interface TOSegmentedControlItem : NSObject |
| 40 | + |
| 41 | +/** When item is a label, the text to display */ |
| 42 | +@property (nonatomic, copy) NSString *title; |
| 43 | + |
| 44 | +/** When item is an image, the image to display */ |
| 45 | +@property (nonatomic, strong) UIImage *image; |
| 46 | + |
| 47 | +/** Whether the item can be tapped to toggle direction */ |
| 48 | +@property (nonatomic, assign) BOOL isReversible; |
| 49 | + |
| 50 | +/** Whether the item is currently reveresed or not */ |
| 51 | +@property (nonatomic, assign) BOOL isReversed; |
| 52 | + |
| 53 | +/** Whether this item is enabled or disabled. */ |
| 54 | +@property (nonatomic, assign) BOOL isDisabled; |
| 55 | + |
| 56 | +/** The view (either image or label) for this item */ |
| 57 | +@property (nonatomic, readonly) UIView *itemView; |
| 58 | + |
| 59 | +/** If the item is a string, the subsequent label view (nil if an image) */ |
| 60 | +@property (nonatomic, nullable, readonly) UILabel *label; |
| 61 | + |
| 62 | +/** If the item is an image, the subsequent image view (nil if a string) */ |
| 63 | +@property (nonatomic, nullable, readonly) UIImageView *imageView; |
| 64 | + |
| 65 | +// Create an array of objects given an array of strings and images |
| 66 | ++ (NSArray *)itemsWithObjects:(NSArray *)objects |
| 67 | + forSegmentedControl:(TOSegmentedControl *)segmentedControl;; |
| 68 | + |
| 69 | +// Create a non-reversible item from this class |
| 70 | +- (nullable instancetype)initWithObject:(id)object |
| 71 | + forSegmentedControl:(TOSegmentedControl *)segmentedControl; |
| 72 | +- (instancetype)initWithTitle:(NSString *)title |
| 73 | + forSegmentedControl:(TOSegmentedControl *)segmentedControl; |
| 74 | +- (instancetype)initWithImage:(UIImage *)image |
| 75 | + forSegmentedControl:(TOSegmentedControl *)segmentedControl; |
| 76 | + |
| 77 | +// Create a potentially reversible item from this class |
| 78 | +- (instancetype)initWithTitle:(NSString *)title |
| 79 | + reversible:(BOOL)reversible |
| 80 | + forSegmentedControl:(TOSegmentedControl *)segmentedControl; |
| 81 | +- (instancetype)initWithImage:(UIImage *)image |
| 82 | + reversible:(BOOL)reversible |
| 83 | + forSegmentedControl:(TOSegmentedControl *)segmentedControl ; |
| 84 | + |
| 85 | +// If the item is reversible, flip the direction |
| 86 | +- (void)toggleDirection; |
| 87 | + |
| 88 | +// Re-synchronize the item view when the segmented control style changes |
| 89 | +- (void)refreshItemView; |
| 90 | + |
| 91 | +@end |
| 92 | + |
| 93 | +NS_ASSUME_NONNULL_END |
0 commit comments