Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: spromicky/StepSlider
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.7.0
Choose a base ref
...
head repository: spromicky/StepSlider
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 10 commits
  • 13 files changed
  • 2 contributors

Commits on Oct 10, 2020

  1. implements support for NSAttributedString

    #46 closed
    spromicky committed Oct 10, 2020
    Copy the full SHA
    62df340 View commit details
  2. Copy the full SHA
    ae30b65 View commit details
  3. minor updated

    spromicky committed Oct 10, 2020
    Copy the full SHA
    4f6c717 View commit details
  4. fix #47

    spromicky committed Oct 10, 2020
    Copy the full SHA
    3ac3657 View commit details
  5. support SPM

    spromicky committed Oct 10, 2020
    Copy the full SHA
    c80b4e8 View commit details
  6. update podspec

    spromicky committed Oct 10, 2020
    Copy the full SHA
    bb490b8 View commit details
  7. update version

    spromicky committed Oct 10, 2020
    Copy the full SHA
    f018afb View commit details
  8. update README.md

    spromicky committed Oct 10, 2020
    Copy the full SHA
    3d5eb89 View commit details

Commits on Jun 15, 2021

  1. Update README.md for latest version

    Installation instruction updated for Cocoapods and Carthage for latest version
    mrugeshtank authored Jun 15, 2021
    Copy the full SHA
    72ef564 View commit details
  2. Merge pull request #53 from mrugeshtank/master

    Update README.md for latest version
    spromicky authored Jun 15, 2021
    Copy the full SHA
    0835ce7 View commit details
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -26,3 +26,7 @@ profile
*.moved-aside
DerivedData
Carthage/

/.build
/Packages
xcuserdata/
14 changes: 14 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// swift-tools-version:5.1

import PackageDescription

let package = Package(
name: "StepSlider",
platforms: [.iOS(.v10)],
products: [
.library(name: "StepSlider", targets: ["StepSlider"])
],
targets: [
.target(name: "StepSlider")
]
)
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -39,6 +39,10 @@ slider.labels = @[@"Some string", @"another string", @"one more"];

`slider.adjustLabel` - set first and last label to exactly to frame left and right.

From version `1.8.0` StepSlider support `NSAttributedString` as label text.

![](screenshots/attributedString.png)

#### Images

For `1.2.0` and higher you can use images for `sliderCircle ` and `trackCircles`. For `trackCircles` supported two states: `normal` and `selected`.
@@ -62,7 +66,7 @@ For `1.2.0` and higher you can use images for `sliderCircle ` and `trackCircles`
To integrate `StepSlider` into your Xcode project using CocoaPods, specify it in your `Podfile`:
```
pod 'StepSlider', '~> 1.3.0'
pod 'StepSlider', '~> 1.8.0'
```
Then, run the following command:
@@ -76,15 +80,19 @@ $ pod install
To integrate `StepSlider` into your Xcode project using Carthage, specify it in your `Cartfile`:
```
github "spromicky/StepSlider" ~> 1.3.0
github "spromicky/StepSlider" ~> 1.8.0
```
Run `carthage update` to build the framework and drag the built `StepSlider.framework` into your Xcode project.
### Swift Package Manager
Start `1.8.0` StepSlider can be integrated in your Xcode project. When adding new package search `StepSlider` and select version `1.8.0` or above.
### Manual Installation
Just copy `StepSlider` class to your project.
## License
StepSlider is available under the MIT license. See the LICENSE file for more info.
StepSlider is available under the MIT license. See the LICENSE file for more info.
Original file line number Diff line number Diff line change
@@ -84,6 +84,7 @@ - (void)addLayers
_trackLayer = [CAShapeLayer layer];
_sliderCircleLayer = [CAShapeLayer layer];
_sliderCircleLayer.contentsScale = [UIScreen mainScreen].scale;
_sliderCircleLayer.actions = @{@"contents": [NSNull null]};

[self.layer addSublayer:_sliderCircleLayer];
[self.layer addSublayer:_trackLayer];
@@ -183,17 +184,17 @@ - (void)layoutLayersAnimated:(BOOL)animated
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
}

_sliderCircleLayer.path = NULL;
_sliderCircleLayer.contents = nil;

if (self.sliderCircleImage) {
_sliderCircleLayer.path = NULL;
_sliderCircleLayer.frame = CGRectMake(0.f, 0.f, fmaxf(self.sliderCircleImage.size.width, 44.f), fmaxf(self.sliderCircleImage.size.height, 44.f));
_sliderCircleLayer.contents = (__bridge id)self.sliderCircleImage.CGImage;
_sliderCircleLayer.contentsGravity = kCAGravityCenter;
} else {
CGFloat sliderFrameSide = fmaxf(self.sliderCircleRadius * 2.f, 44.f);
CGRect sliderDrawRect = CGRectMake((sliderFrameSide - sliderDiameter) / 2.f, (sliderFrameSide - sliderDiameter) / 2.f, sliderDiameter, sliderDiameter);

_sliderCircleLayer.contents = nil;
_sliderCircleLayer.frame = CGRectMake(0.f, 0.f, sliderFrameSide, sliderFrameSide);
_sliderCircleLayer.path = [UIBezierPath bezierPathWithRoundedRect:sliderDrawRect cornerRadius:sliderFrameSide / 2].CGPath;
_sliderCircleLayer.fillColor = [self.sliderCircleColor CGColor];
@@ -249,7 +250,8 @@ - (void)layoutLayersAnimated:(BOOL)animated
trackCircle = _trackCirclesArray[i];
} else {
trackCircle = [CAShapeLayer layer];
trackCircle.actions = @{@"fillColor": [NSNull null]};
trackCircle.actions = @{@"fillColor": [NSNull null],
@"contents": [NSNull null]};

[self.layer addSublayer:trackCircle];

@@ -356,11 +358,19 @@ - (CGFloat)labelHeightWithMaxWidth:(CGFloat)maxWidth
} else {
size = CGSizeMake([self roundForTextDrawing:maxWidth], CGFLOAT_MAX);
}

CGFloat height = [self.labels[i] boundingRectWithSize:size
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : self.labelFont}
context:nil].size.height;

CGFloat height;

if ([self.labels[i] isKindOfClass:[NSString class]]) {
height = [self.labels[i] boundingRectWithSize:size
options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName : self.labelFont}
context:nil].size.height;
} else {
height = [self.labels[i] boundingRectWithSize:size
options:NSStringDrawingUsesLineFragmentOrigin
context:nil].size.height;
}
labelHeight = fmax(ceil(height), labelHeight);
}
return labelHeight;
@@ -620,11 +630,38 @@ - (void)setTintColor:(UIColor *)tintColor
[self setNeedsLayout];
}

- (void)setLabels:(NSArray<NSString *> *)labels
- (void)setLabels:(NSArray *)labels
{
NSAssert(labels.count != 1, @"Labels count can not be equal to 1!");
if (_labels != labels) {
_labels = labels;

NSMutableArray *mLabels = [NSMutableArray arrayWithArray:labels];
for (NSUInteger i = 0; i < labels.count; i++) {
BOOL isAttributedString = [labels[i] isKindOfClass:[NSAttributedString class]];
NSAssert([labels[i] isKindOfClass:[NSString class]] || isAttributedString, @"Labels must be an instance of NSString or NSAttributedString!");

if (isAttributedString) {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithAttributedString: labels[i]];
NSRange fullRange = NSMakeRange(0, attributedString.length);

[attributedString enumerateAttribute:NSFontAttributeName inRange:fullRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {

if (!value) {
[attributedString addAttribute:NSFontAttributeName value:self.labelFont range:range];
}
}];
[attributedString enumerateAttribute:NSForegroundColorAttributeName inRange:fullRange options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {

if (!value) {
[attributedString addAttribute:NSForegroundColorAttributeName value:self.labelColor range:range];
}
}];

mLabels[i] = attributedString;
}
}

if (_labels != mLabels) {
_labels = mLabels;

if (_labels.count > 0) {
_maxCount = _labels.count;
Original file line number Diff line number Diff line change
@@ -82,9 +82,10 @@ IB_DESIGNABLE

/**
* Text for labels that will be show near every dot.
* Note: If `labels` array not empty set `maxCount` to labels count.
* The text must be an instance of `NSString` or `NSAttributedString`.
* Note: If `labels` array are not empty, then `maxCount` will be equal to `labels.count`.
*/
@property (nonatomic, strong) NSArray <NSString *> *labels;
@property (nonatomic, strong) NSArray *labels;

/**
* Font of dot labels.
4 changes: 2 additions & 2 deletions StepSlider.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "StepSlider"
s.version = "1.7.0"
s.version = "1.8.0"
s.summary = "StepSlider its custom implementation of slider such as UISlider for preset values. Its based on drawing directly on CAShapeLayer."
s.homepage = "https://github.com/spromicky/StepSlider"
s.screenshots = "https://github.com/spromicky/StepSlider/blob/master/screenshots/example.gif?raw=true"
@@ -11,5 +11,5 @@ Pod::Spec.new do |s|
s.platform = :ios, '10.0'
s.requires_arc = true

s.source_files = 'StepSlider/source/StepSlider/*'
s.source_files = 'Sources/StepSlider/**/*'
end
22 changes: 11 additions & 11 deletions StepSlider.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -13,11 +13,11 @@
01C688631BCF98C400DB7828 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 01C688621BCF98C400DB7828 /* ViewController.m */; };
01C688661BCF98C400DB7828 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 01C688641BCF98C400DB7828 /* Main.storyboard */; };
01C6886B1BCF98C400DB7828 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 01C688691BCF98C400DB7828 /* LaunchScreen.storyboard */; };
427BAD3D253252E00057EE3E /* StepSlider.h in Headers */ = {isa = PBXBuildFile; fileRef = 427BAD3C253252E00057EE3E /* StepSlider.h */; };
427BAD40253252E80057EE3E /* StepSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 427BAD3F253252E80057EE3E /* StepSlider.m */; };
42F0F56E20DD111B0046AF6D /* StepSlider.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42F0F56720DD111B0046AF6D /* StepSlider.framework */; };
42F0F56F20DD111C0046AF6D /* StepSlider.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 42F0F56720DD111B0046AF6D /* StepSlider.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
42F0F57620DD11270046AF6D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42F0F57520DD11270046AF6D /* UIKit.framework */; };
42F0F57920DD116A0046AF6D /* StepSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 01C688741BCF995F00DB7828 /* StepSlider.m */; };
42F0F57C20DD16460046AF6D /* StepSlider.h in Headers */ = {isa = PBXBuildFile; fileRef = 01C688731BCF995F00DB7828 /* StepSlider.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
@@ -55,8 +55,8 @@
01C688651BCF98C400DB7828 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
01C6886A1BCF98C400DB7828 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
01C6886C1BCF98C400DB7828 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../Info.plist; sourceTree = "<group>"; };
01C688731BCF995F00DB7828 /* StepSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StepSlider.h; sourceTree = "<group>"; };
01C688741BCF995F00DB7828 /* StepSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StepSlider.m; sourceTree = "<group>"; };
427BAD3C253252E00057EE3E /* StepSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StepSlider.h; path = Sources/StepSlider/include/StepSlider.h; sourceTree = SOURCE_ROOT; };
427BAD3F253252E80057EE3E /* StepSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StepSlider.m; path = Sources/StepSlider/StepSlider.m; sourceTree = SOURCE_ROOT; };
42F0F56720DD111B0046AF6D /* StepSlider.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = StepSlider.framework; sourceTree = BUILT_PRODUCTS_DIR; };
42F0F56A20DD111B0046AF6D /* StepSlider-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "StepSlider-Info.plist"; path = "StepSlider/StepSlider-Info.plist"; sourceTree = "<group>"; };
42F0F57520DD11270046AF6D /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
@@ -181,8 +181,8 @@
42F0F57E20DD1F860046AF6D /* StepSlider */ = {
isa = PBXGroup;
children = (
01C688731BCF995F00DB7828 /* StepSlider.h */,
01C688741BCF995F00DB7828 /* StepSlider.m */,
427BAD3C253252E00057EE3E /* StepSlider.h */,
427BAD3F253252E80057EE3E /* StepSlider.m */,
);
path = StepSlider;
sourceTree = "<group>";
@@ -194,7 +194,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
42F0F57C20DD16460046AF6D /* StepSlider.h in Headers */,
427BAD3D253252E00057EE3E /* StepSlider.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -244,7 +244,7 @@
01C688501BCF98C300DB7828 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1100;
LastUpgradeCheck = 1200;
ORGANIZATIONNAME = spromicky;
TargetAttributes = {
01C688571BCF98C300DB7828 = {
@@ -311,7 +311,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
42F0F57920DD116A0046AF6D /* StepSlider.m in Sources */,
427BAD40253252E80057EE3E /* StepSlider.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -499,7 +499,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.8.0;
PRODUCT_BUNDLE_IDENTIFIER = com.spromicky.StepSlider;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
@@ -532,7 +532,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.8.0;
PRODUCT_BUNDLE_IDENTIFIER = com.spromicky.StepSlider;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
PROVISIONING_PROFILE_SPECIFIER = "";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1100"
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Loading