add background image to UITableViewController in Navigation based app(在基于导航的应用程序中将背景图像添加到 UITableViewController)
问题描述
我有一个基于导航的应用程序,我将 UITableViewControllers 推送到堆栈上.我想为我的所有 UITableViewControllers 添加背景 UImage.不是 UIColor,而是 UImage.我知道如何使用 Nib 文件并将 UITableView 本身设置为使用 [UIColor ClearColor],但我没有想要浏览我所有的 UITableViewControllers 并将它们更改为使用 Nib 文件等.
I have a navigation based app where I push UITableViewControllers onto the stack. I would like to add a background UImage to all of my UITableViewControllers. Not a UIColor, but an UImage. I know how I can do this using a Nib file and setting the UITableView itself to have use [UIColor ClearColor], but I don't want to go through all my UITableViewControllers and change them to using Nib files, etc.
我还发现 这个解决方案 如果我只是在我的应用程序中使用单个 tableviewcontroller,那就太好了.我认为可能有一种方法可以通过在 UITableViewController 中默认创建的表视图下方"添加子视图来完成这项工作?
I also found this solution which would be great if I was just using a single tableviewcontroller in my app. I think there might be a way to make this work, by adding a subview "below" my table view that is created by default in a UITableViewController?
任何建议都会很棒.
推荐答案
在基于导航的应用程序中有点不同:只需更改每个表格视图所在的导航视图的背景.在每个 UITableViewController 的 viewDidLoad 中放置以下代码即可:
It's a little different in a navigation based app: just change the background of the navigation view that each table view is sitting on. Placing the following code in viewDidLoad of each UITableViewController works:
self.navigationController.view.backgroundColor =
[UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
但是您可能只需要在导航控制器的顶层执行一次,而不是在每个 tableview 控制器中执行一次(尽管您仍然必须将每个背景设置为清除).
But you may only need to do it once, at the top level of the navigation controller, rather than in each tableview controller (although you'll still have to set each background to clear).
这篇关于在基于导航的应用程序中将背景图像添加到 UITableViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在基于导航的应用程序中将背景图像添加到 UITableViewController
基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
