My code so far in getting slider to work with custom background image
self.slider.setThumbImage(#imageLiteral(resourceName: "thumb"), for: .normal)
self.slider.setMinimumTrackImage(#imageLiteral(resourceName: "slider"), for: .normal)
self.slider.setMaximumTrackImage(#imageLiteral(resourceName: "slider2"), for: .normal)
self.slider.setValue(0.5, animated: true)
I want a slider like temperature where user scroll and it fill with color. But unable to do so. Please help
This one is not working anymore
Dashed slider
Related
Xcode 12.0.1
I am trying to remove the title label text on a UIButton using the storyboard. I then plan on setting it programmatically. When removing the text via the storyboard, the preview shows the text removed. However, the text remains when I build and run the application.
Changing programmatically is not working either. I try to change in in the controllers viewDidLoad()
punchBtn.setTitle("Transfer", for: .normal)
punchBtn.setTitle("Transfer", for: .application)
punchBtn.setTitle("Transfer", for: .selected)
punchBtn.setTitle("Transfer", for: .reserved)
punchBtn.setTitle("Transfer", for: .highlighted)
punchBtn.setTitle("Transfer", for: .disabled)
punchBtn.setTitle("Transfer", for: .focused)
The interesting thing is the text is changing when the button is selected:
Any advice would be greatly appreciated.
In the file Main.strings you will find this word "punch".
change it from there or else take a new button.
This does sound like a cache issue, because nowhere in the app does it say "Punch" anymore.
Command-Shift-K to clean the project hopefully fixes that.
If that doesn't work, then search the entire workspace for instances where you used the word "punch".
Try this!!!
override func viewWillAppear(_ animated: Bool) {
// other code
// end of method
// Change the text of your button
}
I'd like to put a background color for just the title of TabBar using swift I tried to use NSAttributedString.Key.backgroundColor but it not appears color in the background.
Can anybody help me to change the background color for just the title of TabBar?
I need to add yellow color to the background to title in the normal state not selected.
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor.white], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor.gray], for: .selected)
This works for a single item. If you'd like to change the color for all items in the tab bar, try parsing through them like such
for item in self.tabBar.items! {
item.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor.white], for: .normal)
item.appearance().setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor.gray], for: .selected)
}
you can add the following code snippet to your viewDidLoad:
UITabBar.appearance().barTintColor = UIColor.black // your color
I have a button here, and set two different images for two different state:
button.setImage(image1, for: .normal)
button.setImage(image2, for: .selected)
now i want to add an animation on the button's imageview when the button' state changed, so how can i make it? if anyone can help me ,thanks a lot!
Do it like this
button.setIMage(image1, for: .normal)
UIView.animate(withDuration: 0.5) {
button.setImage(image2, for: .selected)
}
I have three buttons link, share and favourites in my cell. I have manually set the images in my custom cell class. In the willDisplay method of tableview delegate I want favourites image to update after the user taps on it. The service is working fine on the backend and the object is being added/removed from the favourites but the image is not updating. I have tried setting up the background image instead of image and also deployed various techniques prescribed for Objective-C but nothing seems to workout in my case. Initially I was setting up the image as the same in the DealsFullTableViewCell
This is willdisplay code snippet I'm talking about
if (self.dealArray[indexPath.row].imageUrl.characters.count > 0){
let cell = tableView.dequeueReusableCell(withIdentifier: "DealsFullTableViewCell", for: indexPath) as! DealsFullTableViewCell
if DataBaseReadServices().getFavourtiesforItemId(self.dealArray[indexPath.row].dealId) == nil {
cell.favouritesButton.setImage(UIImage(named: "Favourites Blue Outline 20x20"), for: .selected)
} else {
cell.favouritesButton.setImage(UIImage(named: "Favourite Icon Blue 20x20"), for: .selected)
print ("=============")
}
}
I am initializing the image in the DealsFullTableViewCell as
let favouritesButtonImage = UIImage.fontAwesomeIcon(name: .starEmpty, textColor: Constants.AppColours().primaryColour, size: CGSize(width: 20, height: 20), backgroundColor: UIColor.clear)
self.favouritesButton.setImage(favouritesButtonImage, for: .normal)
Please check with below answer, if it is not working please change the thread.
if(DataBaseReadServices().getFavourtiesforItemId(self.dealArray[indexPath.row].dealId) == nil){
cell.favouritesButton.setImage(UIImage(named: "Favourites Blue Outline 20x20"), for: .selected)
} else {
cell.favouritesButton.setImage(UIImage(named: "Favourite Icon Blue 20x20"), for: .normal)
print ("=============")
}`
Change the thread if above code is not working.
DispatchQueue.main.async {
//your code
}
Thanks
I set buttons images for normal state and some images is loaded and others appears white.
I need help how to recognize the problem ?
I set the image using the code below
button.setImage(UIImage(named: "icon"), forState: .Normal)
Just change
button.setImage(UIImage(named: "icon"), forState: .Normal)
to this
button .setBackgroundImage(image, forState: UIControlState.Normal)