我目前有一个清晰的背景颜色的tableview,因此可以看到它下面的图像。在模拟器它的伟大工程:Tableview背景在模拟器上显示,但在设备上播放时显示为白色
但是,当它的设备上播放的背景变为白色:
的应用仍然正常工作,但它会是不错的保持背景图片。 这是我的代码:
class TabBarController: UITabBarController, UITableViewDelegate, UITableViewDataSource {
var tabBarItems: [UIViewController] = []
var areMessagesVisible: Bool = false
var titleForTabBars: [String] = ["Home", "Inbox", "Rewards", "My Card", "Locations", "My Profile", "Account Activity", "Invite Friends", "About Us", "Settings", "Help"]
var iconNames: [String] = ["Glass", "Mail Tab Bar Icon", "Rewards Tab Bar Icon", "TabBar card icon", "Locations Tab Bar Icon", "", "", "","","",""]
var controllersStoryboardId: [String] = ["homeNavController", "inboxNavController", "rewardsNavController", "cardNavController", "locationsNavController", "myProfileNavController", "accountActivityNavController", "inviteFriendsNavController", "aboutUsNavController", "settingsNavController", "helpNavController" ]
// to manage moreTableView
var moreTableView: UITableView = UITableView()
var currentTableViewDelegate: UITableViewDelegate?
override func viewDidLoad() {
super.viewDidLoad()
self.customizeMoreTableView()
//to REMOVE
areMessagesVisible = true
if !areMessagesVisible{
self.titleForTabBars.removeAtIndex(4)
self.controllersStoryboardId.removeAtIndex(4)
self.iconNames.removeAtIndex(4)
}
for i in 0 ..< controllersStoryboardId.count{
tabBarItems.append(UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier(controllersStoryboardId[i]) as? UINavigationController ?? UINavigationController())
}
// change background image
let backgroundImageView = UIImageView(image: UIImage(named: "Blank Settings"))
backgroundImageView.frame = view.frame
backgroundImageView.contentMode = .ScaleAspectFill
moreNavigationController.topViewController?.view.addSubview(backgroundImageView)
moreNavigationController.topViewController?.view.sendSubviewToBack(backgroundImageView)
let backgroundImageView2 = UIImageView(image: UIImage(named: "background3"))
backgroundImageView2.frame = view.frame
backgroundImageView2.contentMode = .ScaleAspectFill
moreNavigationController.topViewController?.view.addSubview(backgroundImageView2)
moreNavigationController.topViewController?.view.sendSubviewToBack(backgroundImageView2)
//change nav bar color
moreNavigationController.navigationBar.barStyle = UIBarStyle.BlackOpaque
moreNavigationController.navigationBar.barTintColor = UIColor.blackColor()
moreNavigationController.navigationBar.tintColor = UIColor.whiteColor()
}
override func viewWillAppear(animated: Bool) {
for i in 0 ..< tabBarItems.count{
tabBarItems[i].tabBarItem = UITabBarItem(title: titleForTabBars[i], image: UIImage(named: iconNames[i]), selectedImage: UIImage(named: iconNames[i]))
}
self.viewControllers = tabBarItems
}
func customizeMoreTableView(){
moreTableView = self.moreNavigationController.topViewController!.view as? UITableView ?? UITableView()
currentTableViewDelegate = moreTableView.delegate;
moreTableView.delegate = self
moreTableView.dataSource = self;
moreTableView.registerClass(MoreTableViewCell.self, forCellReuseIdentifier: "MoreTableViewCell")
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 50
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let moreCell = tableView.dequeueReusableCellWithIdentifier("MoreTableViewCell", forIndexPath: indexPath) as? MoreTableViewCell ?? MoreTableViewCell()
moreCell.textLabel?.text = titleForTabBars[indexPath.row + 4]
moreCell.textLabel?.textColor = UIColor.whiteColor()
moreCell.imageView?.image = UIImage(named: iconNames[indexPath.row + 4])
moreCell.backgroundColor = UIColor.clearColor()
return moreCell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titleForTabBars.count - 4
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
currentTableViewDelegate?.tableView!(tableView, didSelectRowAtIndexPath: indexPath)
}
}
使用“查看层次结构检查器”查看导致白色背景的原因。 – EmilioPelaez
你的代码是什么样的?你如何设置背景图像? – ZGski
我将代码添加到原始文章中,它是为更多的ViewController关闭TabBarController – SwiftyJD