Remove UISlider Knob or change image swift - ios

I've added a UISlider to the view. I was wondering whether it is possible to remove the knob or just change the image in swift? How can i do this?

The slider knob is called a thumb image, and you can change it with the setThumbImage:forState: method
mySlider.setThumbImage(nil, forState: UIControlState.Normal) // Remove the knob image by setting it to nil, or add your own image.

Change the thumb tint to clear colour from storyboard

For Swift 5.0 or Later Version
for state: UIControl.State in [.normal, .selected, .application, .reserved] {
editorSlider.setThumbImage(UIImage.init(named: "slider_thumb"), for: state)
}

Related

How to set an image to the UIButton in Swift

I want to set an image to the button
But every time when I add an image to the button it shows a huge image and the image doesn't fit the button size. Like this:
yourButton.clipsToBounds = true
yourButton.contentMode = .scaleAspectFill
// Use setBackgroundImage or setImage
yourButton.setBackgroundImage(UIImage(named: "yourImage"), for: .normal)
Change button style from 'Plain' to 'Default'
Click here for the image reference

Center title on the button image

I want to change button image and title programmatically. When design button image and title (plain) on storyboard it is centered no problem. But when ı use;
startButton.setImage(UIImage(named: "StartButton"), for: .normal)
startButton.setAttributedTitle(NSAttributedString(string: "START"), for: .normal)
to change button image and title programmatically. Button title not centered on image. It looks like it's on the left of the image.
This may helps you.
use setBackgroundImage instead of setImage
startButton.setBackgroundImage(UIImage(named: "StartButton"), for: .normal)
hope this solution will solve your problem 😊

How can I change the UIButton "glow" color used when "Shows Touch On Highlight" is enabled?

I have a UIButton with "Shows Touch On Highlight" enabled in the storyboard. It applies a "white" glow to the button when clicked.
However, I have a light grey button and would like to change the glow color so that it's more visible.
I've tried setting the background image for the highlighted control state to black, but it doesn't seem to make a different to the glow. I can change the background color of the button---that all works.
What controls the glow color, if anything? Or do I have to do it manually if I need a different color?
"Shows Touch On Highlight" is a pure convenience, so you do have to do things manually if you want a different effect. Just supply a different image for the highlighted state, one that includes the desired "glow" drawing.
Using a setBackgroundImage on the UIButton you can create a following extension that lets you to set a color for any state you want:
extension UIButton {
func setBackgroundColor(color: UIColor, for state: UIControlState) {
let image = UIImage.image(with: color)
let insets = UIEdgeInsetsMake(0, 0, 0, 0)
let stretchable = image.resizableImage(withCapInsets: insets, resizingMode: .tile)
self.setBackgroundImage(stretchable, for: state)
}
}
Than you just need to set a background color for the .highlighted state:
button.setBackgroundColor(color: UIColor.red, for: .highlighted)
I just hope you don't mind getting your hands dirty with code, I'm not really sure how to do the same from storyboards (I'm not even sure you can do it).

UISlider with different minimumTrackTintColor like shown in image preview

I need to implement change UISlider minimumTrackColor with different color according to user selection. Same like shown in image please check.Check out this example UISlider
you have to setMinimumTrackImage
slider.setMinimumTrackImage(UIImage(named: "CLR"), forState: .Normal)
CLR.png is

Image clicked button issue in Swift

How actually to make sure my button change background image when user click on it?
My code
btn1.setImage(UIImage(named:"dialpad1.png"),forState:UIControlState.Normal)
btn1.setImage(UIImage(named:"dialpad2.png"),forState:UIControlState.Highlighted)
My background image
dialpad1.png
dialpad2.png
My setting
My screen
Try using a "Custom" type in your UIButton instead of "System".
You can change it from IB:
Register your button for touchdown
myButton.addTarget(self, action: "buttonTouchDownAction:", forControlEvents: UIControlEvents.TouchDown)
Register your button for touchupinside
myButton.addTarget(self, action: "buttonTouchUpInsideAction:", forControlEvents: UIControlEvents.TouchUpInside)
func buttonTouchDownAction(sender:UIButton!)
{
//set highlighted image
}
func buttonTouchUpInsideAction(sender:UIButton!)
{
//set unhighlighted image
}
Thanks Midhun MP, your answer is most correct. I already follow what you suggested. I change State Config to Highlighted and select image in Highlight Background Image. No coding at all..

Resources