Comments (7)
Hi @michaeldebo , please link to a minimal project that reproduces the problem. Itโs very hard to fix a problem I canโt reproduce...
from multislider.
I don't know how to produce a link to it, but here is all the relevant code for the slider:
private func configureAgeSlider() {
let age = ProfileDataManager.shared.age
var lowValue: CGFloat = 18
if age - 8 > 18 {
lowValue = CGFloat(age - 8)
}
ProfileDataManager.shared.minAge = Int(lowValue)
var highValue: CGFloat = 90
if age + 8 < 90 {
highValue = CGFloat(age + 8)
}
ageSlider.minimumValue = 18
ageSlider.maximumValue = 90
ageSlider.value = [lowValue, highValue]
ageSlider.orientation = .horizontal
ageSlider.tintColor = UIColor.convertHexColor(hex: "efefef")
ageSlider.thumbImage = UIImage(named: "slider")!
ageSlider.trackWidth = 3
ageSlider.showsThumbImageShadow = false
ProfileDataManager.shared.maxAge = Int(highValue)
ageSlider.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(ageSlider)
let verticalOffset = getSize(large: 80, medium: 60, small: 45)
ageSlider.topAnchor.constraint(equalTo: distanceSlider.bottomAnchor, constant: verticalOffset).isActive = true
ageSlider.leftAnchor.constraint(equalTo: letsNarrowItDownLabel.leftAnchor).isActive = true
ageSlider.rightAnchor.constraint(equalTo: letsNarrowItDownLabel.rightAnchor).isActive = true
ageSlider.heightAnchor.constraint(equalToConstant: 30).isActive = true
ageSlider.addTarget(self, action: #selector(ageSliderChanged(_:)), for: .valueChanged)
addAgeLabel()
addAgeTitleLabel()
addMinimumAgeLabel()
addMaximumAgeLabel()
}
@objc func ageSliderChanged(_ ageSlider: MultiSlider) {
print("thumb \(ageSlider.draggedThumbIndex) moved")
print("now thumbs are at \(ageSlider.value)")
ageSlider.keepsDistanceBetweenThumbs = true
ageSlider.distanceBetweenThumbs = 4
ageLabel.text = "\(Int(ageSlider.value[0])) - \(Int(ageSlider.value[1]))"
ProfileDataManager.shared.minAge = Int(ageSlider.value[0])
ProfileDataManager.shared.maxAge = Int(ageSlider.value[1])
print("Range slider value changed: \(ageSlider.value)")
}
from multislider.
Please provide code I can execute to reproduce the problem, without calling functions that I don't have the code to. See https://stackoverflow.com/help/minimal-reproducible-example for instructions on how to create such code.
I really want to help, but I can't fix what I can't reproduce.
from multislider.
Okay, had some time so I did that for you. I don't get a crash... Here is the code I added to the Example project found in this repo, based on your code:
private func configureAgeSlider() {
let ageSlider = MultiSlider()
ageSlider.minimumValue = 18
ageSlider.maximumValue = 30
let age: CGFloat = 50
let lowValue = max(ageSlider.minimumValue, age - 8)
let highValue = min(ageSlider.maximumValue, age + 8)
ageSlider.value = [lowValue, highValue]
ageSlider.orientation = .horizontal
ageSlider.tintColor = .red
ageSlider.trackWidth = 3
ageSlider.showsThumbImageShadow = false
ageSlider.addTarget(self, action: #selector(ageSliderChanged(_:)), for: .valueChanged)
view.addConstrainedSubview(ageSlider, constrain: .leftMargin, .rightMargin)
view.constrain(ageSlider, at: .top, to: multiSlider, at: .bottom, diff: 16)
// *** test problem here:
ageSlider.valueLabelPosition = .top
ageSlider.distanceBetweenThumbs = 4
}
@objc func ageSliderChanged(_ ageSlider: MultiSlider) {
// *** no need to change slider properties here
print("thumb \(ageSlider.draggedThumbIndex) moved")
print("now thumbs are at \(ageSlider.value)")
print("Range slider value changed: \(ageSlider.value)")
}
(Plus calling configureAgeSlider()
from the end of viewDidLoad()
)
This works for me, please try it and see if you get an error.
from multislider.
Ahh, so I can't use autolayout, no "translatesAutoresizingIntoConstraints = false" and it should work. Got it. Thanks for your help!
from multislider.
Auto layout works fine: view.addConstrainedSubview()
sets translatesAutoresizingIntoConstraints
to false
internally.
from multislider.
I needed to specify ageSlider.valueLabelPosition and it works. That's what my code was missing. Thx
from multislider.
Related Issues (20)
- Permanently Show Value Labels
- run func at and of drag in SwiftUI HOT 5
- PrivacyInfo.xcprivacy HOT 11
- SwiftUI slider implementation is not displayed correctly on iOS 16.1 simulator HOT 2
- Setting small thumb image makes the thumb difficult to tap on HOT 1
- centerThumbOnTrackEnd(true) makes thumbTouchExpansionRadius unreliable
- images from imageView not showing. HOT 4
- Crashing on iOS 14.6+ - Symbol not found HOT 4
- How to decrease spacing between slider thumb and value label? HOT 4
- How to restrict dragging on condition HOT 5
- 'Multiplier is not finite! That's illegal. multiplier:inf' HOT 1
- UIKit support HOT 1
- Seems that .accentColor is not working HOT 2
- Center Thumb on Track End HOT 2
- Customization of snap views HOT 2
- Can not change thumbs with touch on them HOT 3
- Support for VisionOS, possible cosidering hovering? HOT 1
- Opposing Value Label Positions HOT 1
- How to have each thumb have a different image? HOT 2
- Unable to Compile Project After Update to AvailableHapticFeedback Dependency
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multislider.