Skip to content

Commit 703a9d0

Browse files
authored
Merge pull request #1 from TimOliver/reversible-refactor
Refactor to allow for reversible items more easily
2 parents 8f56ad1 + a970155 commit 703a9d0

9 files changed

Lines changed: 1021 additions & 222 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
x.y.z Release Notes (yyyy-MM-dd)
2+
=============================================================
3+
4+
0.0.1 Release Notes (2019-09-15)
5+
=============================================================
6+
7+
* Initial Release! 🎉

README.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
11
# TOSegmentedControl
2-
A segmented control in the style of iOS 13 for previous versions of iOS.
2+
3+
![TOSegmentedControl](screenshot.jpg)
4+
5+
[![Build status](https://badge.buildkite.com/f88a3dac71358b8341d9f3bedb2342d2ea765bc0efc7207b48.svg)](https://buildkite.com/xd-ci/tosegmentedcontrol-run-ci)
6+
[![Version](https://img.shields.io/cocoapods/v/TOSegmentedControl.svg?style=flat)](http://cocoadocs.org/docsets/TOSegmentedControl)
7+
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
8+
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/TimOliver/TOSegmentedControl/master/LICENSE)
9+
[![Platform](https://img.shields.io/cocoapods/p/TOSegmentedControl.svg?style=flat)](http://cocoadocs.org/docsets/TOSegmentedControl)
10+
[![PayPal](https://img.shields.io/badge/paypal-donate-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=M4RKULAVKV7K8)
11+
[![Twitch](https://img.shields.io/badge/twitch-timXD-6441a5.svg)](http://twitch.tv/timXD)
12+
13+
As part of the visual overhaul featured in iOS 13, `UISegmentedControl` was completely redesigned, featuring a much rounder, cleaner, and slightly more skeuomorphic appearance.
14+
15+
`TOSegmentedControl` is a subclass of of `UIControl` that completely re-implements the look and feel of the new `UISegmentedControl` component, allowing developers to adopt its look even in previous versions of iOS they support.
16+
17+
# Features
18+
19+
* Recreates the new look of `UISegmentedControl`, making it available on previous versions of iOS.
20+
* Supports both text and images as segment types.
21+
* Configurable to dynamically add or remove items after its creation.
22+
* Written in Objective-C, but provides full compatibility with Swift.
23+
* Provides both a block, or `UIControlEvents` to receive when the control is tapped.
24+
* **(TODO)** A reversible mode where tapping the same item twice flips its direction.
25+
* **(TODO)** Light and dark mode support for iOS 13.
26+
27+
# Sample Code
28+
29+
`TOSegmentedControl` has been written to follow the interface of `UISegmentedControl` as closely as possible. This should make it very intuitive to work with.
30+
31+
```Swift
32+
33+
let segmentedControl = SegmentedControl(items: ["First", "Second", "Third"])
34+
segmentedControlsegmentTappedHandler = { segmentIndex, reversed in
35+
print("Segment \(segmentIndex) was tapped!")
36+
}
37+
```
38+
39+
## System Requirements
40+
iOS 10.0 or above
41+
42+
# Installation
43+
44+
<details>
45+
<summary><strong>CocoaPods</strong></summary>
46+
47+
Add the following to your Podfile:
48+
``` ruby
49+
pod 'TOSegmentedControl'
50+
```
51+
</details>
52+
53+
<details>
54+
<summary><strong>Carthage</strong></summary>
55+
56+
1. Add the following to your Cartfile:
57+
```
58+
github "TimOliver/TOSegmentedControl"
59+
```
60+
61+
2. Run `carthage update`
62+
63+
3. From the `Carthage/Build` folder, import the `TOSegmentedControl.framework`.
64+
65+
4. Follow the remaining steps on [Getting Started with Carthage](https://github.com/Carthage/Carthage#getting-started) to finish integrating the framework.
66+
67+
</details>
68+
69+
<details>
70+
<summary><strong>Manual Installation</strong></summary>
71+
72+
All of the necessary source files located in the `TOSegmentedControl` folder. Simply drag that folder into your Xcode project.
73+
</details>
74+
75+
# Credits
76+
77+
`TOSegmentedControl` was created by [Tim Oliver](http://twitter.com/TimOliverAU) as a component for [iComics](http://icomics.co).
78+
79+
iOS device mockup by [Pixeden](http://www.pixeden.com).
80+
81+
# License
82+
83+
`TOSegmentedControl` is available under the MIT license. Please see the [LICENSE](LICENSE) file for more information. ![analytics](https://ga-beacon.appspot.com/UA-5643664-16/TOSegmentedControl/README.md?pixel)
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)