This is the first time I'm using a UITabBar and I'm having problems getting it looking the way I want to look.
Right now it still has some grey shadow over cast over it. I cannot seem to remove this!
I've added this line to my code but the shadow still keeps showing up:
self.universalTabBar.setValue(true, forKey: "_hidesShadow");
Can anyone tell me what I'm doing wrong?
Try setting the rendering mode of each tab bar item's image.
universalTabBar.tintColor = UIColor.whiteColor()
for tabBarItem in universalTabBar.items! {
tabBarItem.image = image.imageWithColor(UIColor.whiteColor()).imageWithRenderingMode(.AlwaysOriginal)
}
Related
I wish to change the image of a tab bar item to a new image at runtime subject to a different view being updated.
Is there any way to achieve this?
I've struggled for hours now so any help would be massively appreciated.
Swift 4.2 Xcode 10.1
EDIT:
I've tried setting through self.tabBarController?.tabBar.items?[0].image in viewDidLoad in my VC. I've tried sub classing a TabBarController and setting through there, to which I couldn't get the runtime behaviour I was after.
To be more clear, i'm happy with my current selected and non selected image called "globe", but I want to listen out to a variable called "truth" and when truth is true I want to change the non selected image to "globe_red".
It is that behaviour of changing the image during the apps runtime that I am struggling with!
You can use following code to change image of tabBar.
self.tabBarController?.tabBar.items?[0].image = #imageLiteral(resourceName: "img")
or for selectedImage
self.tabBarController?.tabBar.items?[0].selectedImage = #imageLiteral(resourceName: "img")
Instead of 0 in items, you can use your index for selected tabBar.
Ok I fixed it!
Subclass UITabBarController
In viewDidLoad of your subclass set self.tabBar.items?[0].image and self.tabBar.items?[0].selectedImage to your desired image. Here I am settings the first VC's tab bar item but you can set any with the index or loop through and set all.
This is probably a simple fix, but I haven't been able to figure out what's going on.
I have a UITableView that looks like this:
When I scroll up, however, the cells are visible behind the title, like so:
I've tried changing the navigation bar to opaque in appDelegate:
UINavigationBar.appearance().isOpaque = true
I have also tried editing the top insets on the UITableView without success. Any thoughts?
If anyone else has the same problem, I just had to set the UINavigationBar tint color like so, and make it non-translucent:
UINavigationBar.appearance().barTintColor = colorDict[currentClerkship]
UINavigationBar.appearance().isTranslucent = false
Ok, so I don't understand why this happens sometimes. When you first drag in a UITableView into your .xib, the tableView background looks white. Then if you change it to another color, and try to switch back to the default with the slash in it, or even white, the TableView shows black. See image
The tableview is set to white. The View for the view controller is set to white, yet I see black in the .xib. However when I actually run the app, it does show white correctly. It just bothers me that I see black like this and don't know why. Does this happen to other ppl? Thanks.
Yeah this happens quite frequently. It's not only related to the UITableViewCell but it can happen on all UIViews.
I've stopped using the default value and instead select the actual color even though they are the same. It is only when selecting default it will give this kind of results.
Explicitly setting the background color setting to White solves the problem.
However I'd be interested to know the correct answer to the change in behavior of the default setting.
Basically switching background color back to 'default' color after having set it to black with unknown temporal circumstances, the background color doesn't switch back to the default white like when first dragged into storyboard.
I'm not able to find any setting related to the default behavior either. Could be a small bug?
I've managed to change the navBar tint, the background color and labels' color using this.
But is it possible to change the icons' color?
(those left to tableview's labels)
Thanks!
I don't know of a way to change the icon colors, but I don't really think all this hacking is necessary anyway - Apple certainly doesn't recommend it.
As far as I can tell, there is nothing special about the moreViewController, apart from being hard to customize. If it were me, I'd simply create my own custom viewcontroller, say MoreViewController, as a subclass of UITableViewController, add it to a NavigationController and then add that as the fifth and last item in the TabBarController. This table would then have a cell for each additional viewcontroller that I'd like to show. Then I'd be free to customize these cells to my heart's content.
This is an old question, nevertheless I'll post a fairly reasonable solution I found.
I first tried setting the global tint color to what I wanted, but that didn't work. Luckily, simply changing the tint color of the table view did work. Adapting code from here:
let color: UIColor
// ...
if let moreTableView = moreNavigationController.topViewController?.view as? UITableView {
moreTableView.tintColor = color
}
This still doesn't seem to affect the edit view controller, however.
EDIT:
There is actually a simpler way to do both, see this answer.
I'm trying to have a button on the self.navigationItem.rightButton that toggles a segmented control that is placed in self.navgivationItem.titleView .. this will however remove the title that is first set by self.title when the navbar is created .. I dont know if my approach is bad but I figured I could rotate between a UILabel and the Segmented Control in the titleView.
It works as I would like it to, however I cant figure out what size and font and shadowoffset and shadowcolor the default titles in a navigation bar is .. could you help me with a solution that either not force me to override the navigationItem.titleView or help me figure out the information needed to make a UILabel look exactly like the default titles.
Thankful for any help.
In code, something along the lines of:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/11648-change-uisegmentedcontrol-font-size.html
should help, except you'll be querying the size, name etc. of the UILabel.