Make UISlider height larger?
I found what I was looking for. The following method just needs to be edited in a subclass.
override func trackRect(forBounds bounds: CGRect) -> CGRect {
var customBounds = super.trackRect(forBounds: bounds)
customBounds.size.height = ...
return customBounds
}
UISlider track not increasing in thickness
As mentioned in many other answers, you can change the height by creating a custom slider as below,
class CustomSlider: UISlider {
override func trackRect(forBounds bounds: CGRect) -> CGRect {
var rect = super.trackRect(forBounds: bounds)
rect.size.height = 7
return rect
}
}
But in your particular case, you are not seeing the change because your implementation is not allowing the factionSlider
to use overridden
trackRect
. To use that you need to change that to CustomSlider
as below,
class FactionButton: UISlider {
var factionSlider = CustomSlider()
func factionBalanceSlider(){
factionSlider.frame = CGRect(x: 15, y: 542, width: 386, height: 57)
factionSlider.minimumValueImage = #imageLiteral(resourceName: "Alliance Slider")
factionSlider.maximumValueImage = #imageLiteral(resourceName: "Horde Slider")
factionSlider.setThumbImage(#imageLiteral(resourceName: "Thumb Image"), for: .normal)
factionSlider.minimumTrackTintColor = UIColor(red:0.08, green:0.33, blue:0.69, alpha:0.8)
factionSlider.maximumTrackTintColor = UIColor(red:1.00, green:0.00, blue:0.00, alpha:0.59)
factionSlider.setValue(0.5, animated: true)
factionSlider.isContinuous = true
factionSlider.addTarget(self, action: #selector(recordFactionBalance(sender:)) , for: .valueChanged)
}
func getSlider() -> UISlider {
return factionSlider
}
}
Note In Swift
, class
name should start with Capital as i updated above. Secondly, I think FactionButton
should not be a subclass
of UISlider
.
UISlider custom images and thumb height?
It turns out setting my slider values in the views did load method was causing problems. I set them in Interface Builder and that was fixed. Once set in IB I can tweak them in code if needs be with no problems.
As for my other problem, I'm wondering if this is because I'm not testing on an actual device, so I'm going to pause that question until I get it on the device in a few weeks.
Custom UISlider - Increase hot spot size
I ended up subclassing the UISlider and overriding this method:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent*)event {
CGRect bounds = self.bounds;
bounds = CGRectInset(bounds, -10, -15);
return CGRectContainsPoint(bounds, point);
}
This extends the touchable area by 10 pixels on the left and right and 15 pixels on the top and bottom.
How to change the size of a UISlider thumb when seeking
Create a normal and larger thumb image with the sizes you want as PDF and add it to the .xcassets.
Then use the following lines of code:
let normal = UIImage(named: "thumbSmall")
slider.setThumbImage(normal, for: .normal)
let highlighted = UIImage(named: "thumbLarger")
slider.setThumbImage(highlighted, for: .highlighted)
Then during sliding the larger thumb image is shown.
A short test looks like this:
bigger UISlider ok but tracking zone problem
I believe that you may want to look at thumbRectForBounds:trackRect:value:
Customizing UISlider look
I believe you'll have to write your own slider to do that. There seems to be no (public) API to change UISlider's behavior regarding the stretchable region.
How to change specified image size in UIImageView with UISlider in Swift programmatically
Make the slider's value range from .01 to 1.0 (.01 should work better than 0.)
Control-drag from your slider into your view controller and create an action on the slider's valueChanged event. Let's call it sliderChanged
.
In the slider's action method, change the scale on the image view:
@IBOutlet myImageView: UIImageView*
@IBAction func sliderChanged(sender: UISlider) {
let scale = sender.value
let transform = CGAffineTransform.scale(scaleX: scale, y: scale)
myImageView.transform = transform
}
That should do it.
Related Topics
iOS Swift Converting Calendar Component Int Month to Medium Style String Month
How to Set Accessibility Identifier in Interface Builder? Xcode4.2
How to Use iOS Speech Recognition in Offline Mode
Change Background of Uicollectionview Cell on Tap
Less Blur with 'Visual Effect View with Blur'
Add a View on Top of the Keyboard Using Inputaccessoryview
Creating Slow Scrolling to Indexpath in Uicollectionview
Debugging Mobile Safari in iOS 8 and iOS 9
Unrecognized Selector Sent to Instance While Archiving Data (Nscoding)
Dynamic Uicollectionview Header Size Based on Uilabel
iOS Enterprise Provisioning Profile Expiration
Uidatepicker Bug? Uicontroleventvaluechanged After Hitting Minimum Internal
Detect Whether a Font Is Bold/Italic on iOS
How to Get Selected Text from Uitextfield in Iphone
Open Wifi Settings by "Prefs:Root=Wifi" Failed in iOS 10
Get Uiwebview Content's Height
Pulling Data from a Cmsamplebuffer in Order to Create a Deep Copy