ajgr / VerticalSlider

A simple iOS app demonstrating several ways of implementing a vertical slider in an iOS app.
4 stars 2 forks source link

Cannot set the custom class #1

Open emmet-temme opened 6 years ago

emmet-temme commented 6 years ago

Hello,

One way of doing this is to add a regular slider. Then in the Identity Inspector set the custom class property to VerticalSlider and hook the slider to an action like any other UISlider.

If I do so in your XCode Project, in the Identity Inspector I can only choose the VerticalUISlider class, but not the VerticalSlider class. How can i set the custom class property to VerticalSlider?

Im using XCode 9.2

Thanks

tomgradel commented 6 years ago

@emmet-temme I needed to change VerticalSlider to subclass UISlider to set the custom class property. After assigning, I could then change it back to subclassing from UIControl.

However, the control is still unusable in my application. I'm getting a "IBDesignable Build Failed" message, and the VerticalSlider class doesn't "take". All the attributes of the slider still appears as a UISlider -- not VerticalSlider. I'm still searching for a solution to this problem. The sample application from GitHub works, so there's some subtle difference between the sample code and mine even though VerticalSlider.swift is identical.

I'm using Xcode 9.2.

tomgradel commented 6 years ago

It turned out that to set the custom class you should not try to subclass a class derived from UISlider despite the author's suggestions. Instead, subclass a view, at which time the VerticalSlider, subclassed from UIControl will appear in the list of potential custom classes. I also needed to exit Xcode and delete DerivedData to eliminate a 'build failed' message.

pearlpdx commented 6 years ago

1) The trackLength is being set before the subviews have resized causing strange results. This also adds support for change in orientation. 2) Needs a way to set the value otherwise it cannot be preset or used in a UICollectionView. 3) As noted above you must use a UIView not a UISlider and it must be the same width as the the thumb, currently 42.

added:

func setValue(value: CGFloat) { self.value = value setNeedsDisplay() }

override func layoutSubviews() { super.layoutSubviews() let tempValue = value trackLength = self.bounds.height - (self.thumbOffset * 2) self.value = tempValue setNeedsDisplay() }