Je travaille sur une application iOS disposant de 4 onglets supplémentaires auxquels l'utilisateur doit pouvoir accéder. J'ai décidé de créer mon propre contrôleur de barre d'onglets personnalisé afin que j'aie plus d'options quand il s'agit de personnalisation. J'ai implémenté le contrôleur de barre d'onglets personnalisé et suis capable de passer d'une vue à une autre, sauf lorsque je dois ajouter des éléments d'interface utilisateur tels que UITextField
, UIButton
, etc. dans mes classes de contrôleur de vue et exécuter l'application les éléments de l'interface utilisateur ne s'affichent pas .Les éléments de l'interface utilisateur n'affichent pas les contrôleurs de vue qui ne font pas partie du contrôleur de la barre d'onglets personnalisée
CustomTabBarController.swift
import UIKit
class CustomTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let socialController = socialViewController()
socialController.navigationItem.title = "Social"
let navigationController = UINavigationController(rootViewController: socialController)
navigationController.title = "Social"
navigationController.tabBarItem.image = UIImage(named: "User-Group-50")
let mapController = GoogleMapsViewController()
mapController.navigationItem.title = "Map"
let MapNavigationController = UINavigationController(rootViewController: mapController)
MapNavigationController.title = "Map"
MapNavigationController.tabBarItem.image = UIImage(named: "Map-50")
let scheduleController = scheduleViewController()
scheduleController.navigationItem.title = "Schedule"
let ScheduleNavigationController = UINavigationController(rootViewController: scheduleController)
ScheduleNavigationController.title = "Schedule"
ScheduleNavigationController.tabBarItem.image = UIImage(named: "Calendar-50")
let settingsController = settingsViewController()
settingsController.navigationItem.title = "Settings"
let SettingsNavigationController = UINavigationController(rootViewController: settingsController)
SettingsNavigationController.title = "Settings"
SettingsNavigationController.tabBarItem.image = UIImage(named: "Settings-50")
viewControllers = [navigationController, MapNavigationController, ScheduleNavigationController, SettingsNavigationController]
tabBar.isTranslucent = true
let topBorder = CALayer()
topBorder.frame = CGRect(x: 0, y: 0, width: 1000, height: 0.5)
topBorder.backgroundColor = UIColor.white.cgColor
tabBar.layer.addSublayer(topBorder)
tabBar.clipsToBounds = true
}
}
AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = CustomTabBarController()
UINavigationBar.appearance().barTintColor = UIColor(red: 200/255, green: 0/255, blue: 0/255, alpha: 1)
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
UITabBar.appearance().tintColor = UIColor(red: 51/255, green: 90/255, blue: 149/255, alpha: 1)
application.statusBarStyle = .lightContent
// Override point for customization after application launch.
return true
}
J'essaie d'ajouter un UITextField
en utilisant:
var textField: UITextField
Mais quand je lance mon application le textField
ne apparaître dans la vue.
Merci pour l'aide qui a fonctionné. – user2569905