How to make UISlider thicker?
Asked Answered
A

2

2

I want to create a really thick horizontally oriented UISlider. I know it is easy to make it longer, but how do I make the track (and therefore the area in which touch events can be registered) thicker?

Apuleius answered 14/11, 2011 at 3:24 Comment(0)
I
9

Subclass the UISlider and then make this modification:

- (CGRect)trackRectForBounds:(CGRect)bounds
{
    return bounds;
}

(I just tried this out in UICatalog -- which is a very nice set of Apple sample code -- and it works perfectly great).

Imprisonment answered 14/11, 2011 at 3:42 Comment(2)
Will I still be able to user Interface Builder to place and setup IBActions of this subclass? Sorry if this is obvious, I'm still relatively new.Apuleius
Yes, just make sure you set the custom class of the item (in Interface Builder) to your subclassed UISlider. Oh, one more thing... you've asked 7 questions and have "accepted" none of them. If you'd like to get more people to help you out here, you should go back and accept the answers that worked best from your previous questions.Imprisonment
K
1

Swift equivalent of Michael's answer:

import UIKit

class ThickSlider: UISlider {

    override func trackRect(forBounds bounds: CGRect) -> CGRect {
        return bounds
    }

}
Kommunarsk answered 4/3, 2020 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.