For one controller I have settings:
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
and
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
var offset = scrollView.contentOffset.y / 150
if offset > 1 {
offset = 1
self.navigationController?.navigationBar.backgroundColor = UIColor(red: 82/255, green: 76/255, blue: 70/255, alpha: offset)
UIApplication.shared.statusBarView?.backgroundColor = UIColor(red: 82/255, green: 76/255, blue: 70/255, alpha: offset)
self.navigationItem.title = name
} else {
self.navigationController?.navigationBar.backgroundColor = UIColor(red: 82/255, green: 76/255, blue: 70/255, alpha: offset)
UIApplication.shared.statusBarView?.backgroundColor = UIColor(red: 82/255, green: 76/255, blue: 70/255, alpha: offset)
self.navigationItem.title = ""
}
}
The main problem is that when i press back button, settings save. In the end i have white NavigationController. How can I make the settings not taken from the last controller?
func makeSearchController() {
searchController = UISearchController(searchResultsController: nil)
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.tintColor = .white
searchController.searchBar.placeholder = "Блюдо или продукт ..."
}
You can reset the navigation controller's color in viewWillDisappear, like this:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.navigationBar.backgroundColor = UIColor(red: 221/255, green: 221/255, blue: 225/255, alpha: offset) //gray color
UIApplication.shared.statusBarView?.backgroundColor = UIColor(red: 221/255, green: 221/255, blue: 225/255, alpha: offset) //gray color
}
Related
Button Method
#objc func buttonFuction(){
let stacView = UIStackView()
stacView.spacing = 12
stacView.distribution = .fillEqually
stacView.axis = .horizontal
stacView.translatesAutoresizingMaskIntoConstraints = false
view!.addSubview(stacView)
buttonNames = ["One","Two","Three","Four"]
for i in 0..<buttonNames.count{
index+=i
button = Button()
button.setTitle(buttonNames[i], for: .normal)
stacView.addArrangedSubview(button)
buttons.append(button)
button.tag = index
button.addTarget(self, action: selectors[i], for: .touchUpInside)
button.addTarget(self, action: selectorsColor[i], for: .touchDown)
}
NSLayoutConstraint.activate([stacView.centerXAnchor.constraint(equalTo: view!.centerXAnchor),stacView.centerYAnchor.constraint(equalTo: view!.centerYAnchor),stacView.widthAnchor.constraint(equalToConstant: 350),stacView.heightAnchor.constraint(equalToConstant:70)])
}
Button handler methods
#objc func colorButton1(){
if button.tag == 0 {
button.backgroundColor = #colorLiteral(red: 0.1123025946, green: 1, blue: 0.03079073749, alpha: 1)
}
else {
button.backgroundColor = #colorLiteral(red: 0.7974829231, green: 0.09321228972, blue: 0.09321228972, alpha: 1)
}
}
#objc func colorButton2(){
if button.tag == 1 {
button.backgroundColor = #colorLiteral(red: 0.07117979832, green: 0.8973241221, blue: 0, alpha: 1)
}
else {
button.backgroundColor = #colorLiteral(red: 0.7312681945, green: 0.1133923198, blue: 0.06002510149, alpha: 1)
}
}
#objc func colorButton3(){
if button.tag == 2 {
button.backgroundColor = #colorLiteral(red: 0.1123025946, green: 1, blue: 0.03079073749, alpha: 1)
}
else {
button.backgroundColor = #colorLiteral(red: 0.6805654408, green: 0.1003367522, blue: 0.09689761347, alpha: 1)
}
}
#objc func colorButton4(){
if button.tag == 3 {
button.backgroundColor = #colorLiteral(red: 0.1123025946, green: 1, blue: 0.03079073749, alpha: 1)
}
else {
button.backgroundColor = #colorLiteral(red: 0.7620294414, green: 0.05229266211, blue: 0.09308676813, alpha: 1)
}
}
Every time I press the button it keeps changing colour to the last button, even after tagging each button, the colour change only occurs in the last button and not sure how to change the code to allow the colour change to happen on other button when pressed.
Thank you in advance.
As I said in the comments, the buttons array contains 4 items which all point – due to reference semantics – to the same instance, the lastly added Button instance. So does also the button property.
You need something like this, it creates four different Button instances and uses one action method, I don't know what the second selector does so I commented it out.
The logic: The sender parameter is the just tapped button, first set all background colors except the current button to their appropriate red colors, then set the background color of the current button to the green color. The references to the buttons are taken from the buttons array.
for i in 0..<buttonNames.count{
let button = Button()
button.setTitle(buttonNames[i], for: .normal)
stacView.addArrangedSubview(button)
buttons.append(button)
button.tag = i
button.addTarget(self, action: #selector(colorButton), for: .touchUpInside)
// button.addTarget(self, action: selectorsColor[i], for: .touchDown)
}
#objc func colorButton(_ sender : Button) {
let offColors = [#colorLiteral(red: 0.7974829231, green: 0.09321228972, blue: 0.09321228972, alpha: 1),
#colorLiteral(red: 0.7312681945, green: 0.1133923198, blue: 0.06002510149, alpha: 1),
#colorLiteral(red: 0.6805654408, green: 0.1003367522, blue: 0.09689761347, alpha: 1),
#colorLiteral(red: 0.7620294414, green: 0.05229266211, blue: 0.09308676813, alpha: 1)]
for i in 0..<4 where i != sender.tag {
buttons[i].backgroundColor = offColors[i]
}
switch sender.tag {
case 0: sender.backgroundColor = #colorLiteral(red: 0.1123025946, green: 1, blue: 0.03079073749, alpha: 1)
case 1: sender.backgroundColor = #colorLiteral(red: 0.07117979832, green: 0.8973241221, blue: 0, alpha: 1)
case 2: sender.backgroundColor = #colorLiteral(red: 0.1123025946, green: 1, blue: 0.03079073749, alpha: 1)
case 3: sender.backgroundColor = #colorLiteral(red: 0.1123025946, green: 1, blue: 0.03079073749, alpha: 1)
default: break
}
}
I am creating an app programitcally (on my first try). I have managed to create a collection view and on the click of the add button in the navigation bar a new cell appears. I want to be able to set all cells created to be editable (in other words show the delete button on the cells) when the edit button in the navigation bar is clicked. Currently no matter what I try whether I click on edit or not, nothing happens. I have tried hiding the UIImage of the button as well as the button by calling a function created in the cell class when the edit button is clicked and have also tried moving this function to the ViewController Class, app runs but code doesn't do what it is supposed to.
My Code:
class CollectionViewController: UICollectionViewController, UITextViewDelegate {
// decelrations of variables for use
let cell = ListCell()
let cellId = "cellId"
var numberOfLists = 0
var lists = [String]()
let secondVC = TableViewController()
// for learning purposes: codes sets up the view programitcally along with what is in scenedelagate
override func viewDidLoad() {
super.viewDidLoad()
setCollectionView()
}
//Function that will generate the collectionView
func setCollectionView() {
collectionView.register(ListCell.self, forCellWithReuseIdentifier: cellId)
collectionView.backgroundColor = .white
navigationItem.title = "Lists"
navigationController?.navigationBar.barTintColor = UIColor(white: 200/255, alpha: 1)
navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white, .font: UIFont.boldSystemFont(ofSize: 20)]
navigationItem.leftBarButtonItem = editButtonItem
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addTapped))
collectionView.delegate = self //runs the delegate flow methods
collectionView.dataSource = self
}
// to do with enabling editing in CV - function tied to edit button
override func setEditing(_ editing: Bool, animated: Bool){
super.setEditing(editing, animated: animated)
if editing {
print ("Editing Mode Enabled")
//cell.showButton()
} else {
print ("Editing Mode Closed")
}
// reloads the view after code is performed
self.collectionView.reloadData()
}
// func when buttons are tapped to add a collection view
#objc func addTapped() {
print("This button should not crash")
numberOfLists += 1
navigationController?.pushViewController(secondVC, animated: true)
collectionView.reloadData()
}
}
// the following block of code has to do with the set up of the collectionView
extension CollectionViewController: UICollectionViewDelegateFlowLayout {
// this code should speficiy how many cells you are going to have in your collectionview
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return numberOfLists
}
// this code lets you reuse a cell
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath)-> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! ListCell
cell.deleteButton.setImage(UIImage.init(named: "delete"), for: .normal)
return cell
}
// this code sets the sizing of the cells
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: (view.frame.width / 2) - 16, height: 100)
}
// where to place the cell on the screen
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 8, left: 9, bottom: 8, right: 8)
}
// this function just checks to see if the cell is selected
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
navigationController?.pushViewController(secondVC, animated: true)
}
}
//this class sets up the collectionViewCell
class ListCell: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
setupCell()
}
fileprivate func setupCell(){
let colors = cellRandomBackgroundColors()
self.backgroundColor = colors[0]
self.addSubview(listNameLabel)
roundCorner()
setCellShadow()
self.addSubview(deleteButton)
deleteButton.addTarget(self, action: #selector(deleteCell), for: .touchUpInside)
}
#objc func deleteCell() {
print ("this button works")
}
func showButton() {
deleteButton.isHidden = true
print ("this is supposed to work")
}
func roundCorner() {
self.contentView.layer.cornerRadius = 50.0
self.contentView.layer.masksToBounds = true
self.contentView.layer.borderWidth = 1.0
self.contentView.layer.borderColor = UIColor.clear.cgColor
}
func setCellShadow() {
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOffset = CGSize(width: 0, height: 1)
self.layer.shadowOpacity = 0.2
self.layer.shadowRadius = 1.0
self.layer.masksToBounds = false
self.layer.cornerRadius = 3
self.clipsToBounds = false
}
func cellRandomBackgroundColors() -> [UIColor] {
//Colors
let red = [#colorLiteral(red: 0.9654200673, green: 0.1590853035, blue: 0.2688751221, alpha: 1),#colorLiteral(red: 0.7559037805, green: 0.1139892414, blue: 0.1577021778, alpha: 1)]
let orangeRed = [#colorLiteral(red: 0.9338900447, green: 0.4315618277, blue: 0.2564975619, alpha: 1),#colorLiteral(red: 0.8518816233, green: 0.1738803983, blue: 0.01849062555, alpha: 1)]
let orange = [#colorLiteral(red: 0.9953531623, green: 0.54947716, blue: 0.1281470656, alpha: 1),#colorLiteral(red: 0.9409626126, green: 0.7209432721, blue: 0.1315650344, alpha: 1)]
let yellow = [#colorLiteral(red: 0.9409626126, green: 0.7209432721, blue: 0.1315650344, alpha: 1),#colorLiteral(red: 0.8931249976, green: 0.5340107679, blue: 0.08877573162, alpha: 1)]
let green = [#colorLiteral(red: 0.3796315193, green: 0.7958304286, blue: 0.2592983842, alpha: 1),#colorLiteral(red: 0.2060100436, green: 0.6006633639, blue: 0.09944178909, alpha: 1)]
let greenBlue = [#colorLiteral(red: 0.2761503458, green: 0.824685812, blue: 0.7065336704, alpha: 1),#colorLiteral(red: 0, green: 0.6422213912, blue: 0.568986237, alpha: 1)]
let kindaBlue = [#colorLiteral(red: 0.2494148612, green: 0.8105323911, blue: 0.8425348401, alpha: 1),#colorLiteral(red: 0, green: 0.6073564887, blue: 0.7661359906, alpha: 1)]
let skyBlue = [#colorLiteral(red: 0.3045541644, green: 0.6749247313, blue: 0.9517192245, alpha: 1),#colorLiteral(red: 0.008423916064, green: 0.4699558616, blue: 0.882807076, alpha: 1)]
let blue = [#colorLiteral(red: 0.1774400771, green: 0.466574192, blue: 0.8732826114, alpha: 1),#colorLiteral(red: 0.00491155684, green: 0.287129879, blue: 0.7411141396, alpha: 1)]
let bluePurple = [#colorLiteral(red: 0.4613699913, green: 0.3118675947, blue: 0.8906354308, alpha: 1),#colorLiteral(red: 0.3018293083, green: 0.1458326578, blue: 0.7334778905, alpha: 1)]
let purple = [#colorLiteral(red: 0.7080290914, green: 0.3073516488, blue: 0.8653779626, alpha: 1),#colorLiteral(red: 0.5031493902, green: 0.1100070402, blue: 0.6790940762, alpha: 1)]
let pink = [#colorLiteral(red: 0.9495453238, green: 0.4185881019, blue: 0.6859942079, alpha: 1),#colorLiteral(red: 0.8123683333, green: 0.1657164991, blue: 0.5003474355, alpha: 1)]
let colorsTable: [Int: [UIColor]] = [0: red, 1: orangeRed, 2: orange, 3: yellow, 4: green, 5: greenBlue, 6: kindaBlue, 7: skyBlue, 8: blue, 9: bluePurple, 10: bluePurple, 11: purple, 12: pink]
let randomColors = colorsTable.values.randomElement()
return randomColors!
}
let deleteButton: UIButton = {
let deleteButton = UIButton(frame: CGRect(x:2,y:2,width:70,height:30))
return deleteButton
}()
let listNameLabel: UILabel = {
let listLabel = UILabel(frame: CGRect(x:2,y:50,width:70,height:30))
listLabel.text = "Data entry on Second View"
listLabel.font = UIFont.boldSystemFont(ofSize: 12)
listLabel.backgroundColor = .green
listLabel.translatesAutoresizingMaskIntoConstraints = false
listLabel.tag = 1
return listLabel
}()
let iconImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "Folder")
imageView.contentMode = .scaleAspectFit
return imageView
}()
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Edit Button on Cells that doesn't disappear
I'm having a problem with trying to display the user location and the MKPolygon Area.
Here is the code about the MapView.swift:
import SwiftUI
import MapKit
let model = Model(filename: "ZONE_LIST")
var mapView = MKMapView() // (frame: UIScreen.main.bounds)
var theme = ""
struct MapView: UIViewRepresentable {
func makeUIView(context: Context) -> MKMapView {
let latDelta = model.overlayTopLeftCoordinate.latitude - model.overlayBottomRightCoordinate.latitude
let span = MKCoordinateSpan(latitudeDelta: fabs(latDelta), longitudeDelta: 0.99)
let region = MKCoordinateRegion(center: model.midCoordinate, span: span)
mapView.showsUserLocation = true
mapView.region = region
mapView.delegate = context.coordinator
return mapView
}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
func updateUIView(_ uiView: MKMapView, context: UIViewRepresentableContext<MapView>) {}
}
The Coordinator file instead is:
import MapKit
final class Coordinator: NSObject, MKMapViewDelegate {
var parent: MapView
init(_ parent: MapView) {
self.parent = parent
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKPolygon {
let polygonView = MKPolygonRenderer(overlay: overlay)
if theme == "Ciano" {
polygonView.strokeColor = .cyan
polygonView.fillColor = .cyan
} else if theme == "Rosso" {
polygonView.strokeColor = .init(red: 255/255, green: 0/255, blue: 0/255, alpha: 1.0)
polygonView.fillColor = .init(red: 255/255, green: 0/255, blue: 0/255, alpha: 1.0)
} else if theme == "Verde" {
polygonView.strokeColor = .init(red: 0/255, green: 255/255, blue: 0/255, alpha: 1.0)
polygonView.fillColor = .init(red: 0/255, green: 255/255, blue: 0/255, alpha: 1.0)
} else if theme == "Magenta" {
polygonView.strokeColor = .magenta
polygonView.fillColor = .magenta
} else if theme == "Giallo" {
polygonView.strokeColor = .yellow
polygonView.fillColor = .yellow
} else if theme == "Arancione" {
polygonView.strokeColor = .init(red: 255/255, green: 153/255, blue: 51/255, alpha: 1.0)
polygonView.fillColor = .init(red: 255/255, green: 153/255, blue: 51/255, alpha: 1.0)
} else if theme == "Verde Turchese" {
polygonView.strokeColor = .init(red: 50/255, green: 198/255, blue: 166/255, alpha: 1.0)
polygonView.fillColor = .init(red: 50/255, green: 198/255, blue: 166/255, alpha: 1.0)
} else if theme == "Blu" {
polygonView.strokeColor = .init(red: 0/255, green: 66/255, blue: 255/255, alpha: 1.0)
polygonView.fillColor = .init(red: 0/255, green: 66/255, blue: 255/255, alpha: 1.0)
} else {
polygonView.strokeColor = .init(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0)
polygonView.fillColor = .init(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0)
}
polygonView.alpha = 0.5
polygonView.lineWidth = 5.0
return polygonView
}
return MKOverlayRenderer()
}
}
To be honest, this is the code in the exact moment I have got the error trying to put the UserLocation on the Project, however the problem is this. I hope someone can help me.
Ok boyz, the problem has been resolved by myself, lol.
I just putted in the Coordinator.swift file the code that print out the marked area.
final class Coordinator: NSObject, MKMapViewDelegate {
var parent: MapView
init(_ parent: MapView) {
self.parent = parent
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is ModelMapOverlay {
return ModelMapOverlayView(overlay: overlay, overlayImage: UIImage(imageLiteralResourceName: "overlay_model"))
} else if overlay is MKPolyline {
let lineView = MKPolylineRenderer(overlay: overlay)
lineView.strokeColor = .green
return lineView
} else if overlay is MKPolygon {
let polygonView = MKPolygonRenderer(overlay: overlay)
if theme == "Ciano" {
polygonView.strokeColor = .cyan
polygonView.fillColor = .cyan
} else if theme == "Rosso" {
polygonView.strokeColor = .init(red: 255/255, green: 0/255, blue: 0/255, alpha: 1.0)
polygonView.fillColor = .init(red: 255/255, green: 0/255, blue: 0/255, alpha: 1.0)
} else if theme == "Verde" {
polygonView.strokeColor = .init(red: 0/255, green: 255/255, blue: 0/255, alpha: 1.0)
polygonView.fillColor = .init(red: 0/255, green: 255/255, blue: 0/255, alpha: 1.0)
} else if theme == "Magenta" {
polygonView.strokeColor = .magenta
polygonView.fillColor = .magenta
} else if theme == "Giallo" {
polygonView.strokeColor = .yellow
polygonView.fillColor = .yellow
} else if theme == "Arancione" {
polygonView.strokeColor = .init(red: 255/255, green: 153/255, blue: 51/255, alpha: 1.0)
polygonView.fillColor = .init(red: 255/255, green: 153/255, blue: 51/255, alpha: 1.0)
} else if theme == "Verde Turchese" {
polygonView.strokeColor = .init(red: 50/255, green: 198/255, blue: 166/255, alpha: 1.0)
polygonView.fillColor = .init(red: 50/255, green: 198/255, blue: 166/255, alpha: 1.0)
} else if theme == "Blu" {
polygonView.strokeColor = .init(red: 0/255, green: 66/255, blue: 255/255, alpha: 1.0)
polygonView.fillColor = .init(red: 0/255, green: 66/255, blue: 255/255, alpha: 1.0)
} else {
polygonView.strokeColor = .init(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0)
polygonView.fillColor = .init(red: 0/255, green: 0/255, blue: 0/255, alpha: 1.0)
}
polygonView.alpha = 0.5
polygonView.lineWidth = 5.0
return polygonView
} else if let character = overlay as? Character {
let circleView = MKCircleRenderer(overlay: character)
circleView.strokeColor = character.color
return circleView
}
return MKOverlayRenderer()
}
}
Hope if someone will got the same problem could see this snippet to resolve it
import UIKit
class MainVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
func backgroundcolor(){
let newLayer = CAGradientLayer()
newLayer.colors = [UIColor.init(red: 0.2705882353, green: 0.4823529412, blue: 0.6156862745, alpha: 1).cgColor,UIColor.init(red: 0.6588235294, green: 0.8549019608, blue: 0.862745098, alpha: 1).cgColor]
newLayer.frame = view.frame
view.layer.addSublayer(newLayer)
}
}
In your viewDidLayoutSubviews, call your function. Any changes related to layout should be done in viewDidLayoutSubviews
import UIKit
class MainVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
backgroundColor()
}
func backgroundcolor(){
let newLayer = CAGradientLayer()
newLayer.colors = [UIColor.init(red: 0.2705882353, green: 0.4823529412, blue: 0.6156862745, alpha: 1).cgColor,UIColor.init(red: 0.6588235294, green: 0.8549019608, blue: 0.862745098, alpha: 1).cgColor]
newLayer.frame = view.frame
self.view.layer.insertSublayer(newLayer, at: 0)
}
}
Try this
let gradientView = UIView()
gradientView.frame = view.bounds
let newLayer = CAGradientLayer()
newLayer.colors = [UIColor.init(red: 0.2705882353, green: 0.4823529412, blue: 0.6156862745, alpha: 1).cgColor,UIColor.init(red: 0.6588235294, green: 0.8549019608, blue: 0.862745098, alpha: 1).cgColor]
newLayer.frame = gradientView.bounds
gradientView.layer.addSublayer(newLayer)
self.view.addSubview(gradientView)
self.view.sendSubviewToBack(gradientView)
I'm trying to implement AZTabBarController within my project but I am struggling to fix the bar to the bottom of the screen. My assumption is that the bar can be fixed to the bottom using some method or that I have some element that is pushing the bar some 50pts higher. Perhaps there is a margin of some sort that keeps the bar from staying at the bottom. Any suggestions will be much appreciated.
Here is my AZTabBar code. I've borrowed it from the example within the repo.
class CustomTabBarController: UITabBarController {
var tabController: AZTabBarController!
override func viewDidLoad() {
super.viewDidLoad()
var icons = [UIImage]()
icons.append(UIImage.init(named: "ic_home")!)
icons.append(UIImage.init(named: "ic_new")!)
icons.append(UIImage.init(named: "ic_settings")!)
//The icons that will be displayed for each tab once they are selected.
var selectedIcons = [UIImage]()
selectedIcons.append(UIImage.init(named: "ic_home")!)
selectedIcons.append(UIImage.init(named: "ic_new")!)
selectedIcons.append(UIImage.init(named: "ic_settings")!)
tabController = AZTabBarController.insert(into: self, withTabIcons: icons, andSelectedIcons: selectedIcons)
tabController.delegate = self
tabController.setViewController(QueryViewController.instance(), atIndex: 0)
tabController.setViewController(SettingsViewController.instance(), atIndex: 2)
//customize
let color = UIColor(red: 14.0/255, green: 122.0/255, blue: 254.0/255, alpha: 1.0)
tabController.selectedColor = color
tabController.highlightColor = color
tabController.highlightedBackgroundColor = #colorLiteral(red: 0.1803921569, green: 0.8, blue: 0.4431372549, alpha: 1)
tabController.defaultColor = .lightGray
//tabController.highlightButton(atIndex: 2)
tabController.buttonsBackgroundColor = UIColor(red: (247.0/255), green: (247.0/255), blue: (247.0/255), alpha: 1.0)//#colorLiteral(red: 0.2039215686, green: 0.2862745098, blue: 0.368627451, alpha: 1)
tabController.selectionIndicatorHeight = 0
tabController.selectionIndicatorColor = color
tabController.tabBarHeight = 60
tabController.setAction(atIndex: 0) {
//Your statments
print("Home!")
}
tabController.setAction(atIndex: 1) {
//Your statments
print("NEW Situation!")
}
tabController.setAction(atIndex: 2) {
//Your statments
print("Settings")
}
tabController.animateTabChange = false
tabController.onlyShowTextForSelectedButtons = false
tabController.setTitle("Home", atIndex: 0)
tabController.setTitle("New", atIndex: 1)
tabController.setTitle("Settings", atIndex: 2)
//tabController.font = UIFont(name: "AvenirNext-Regular", size: 12)
}
override var childForStatusBarStyle: UIViewController?{
return tabController
}
func getNavigationController(root: UIViewController)->UINavigationController{
let navigationController = UINavigationController(rootViewController: root)
navigationController.title = title
navigationController.navigationBar.isTranslucent = false
navigationController.navigationBar.barStyle = .black
navigationController.navigationBar.isTranslucent = false
navigationController.navigationBar.barTintColor = #colorLiteral(red: 0.7450980544, green: 0.1568627506, blue: 0.07450980693, alpha: 1)
return navigationController
}
}
Sub classing
class CustomTabBarController: UITabBarController {
is the reason you should use AZTabBarController directly , what you see as margin in bottom is the parent class's tabBar which is empty because you don't set any viewControllers for it