Ric*_*kiG 7 iphone background-image uitableview
我一直到处都是,似乎UITableView有一个静态的背景问题有很好的记录,但没有人有一个直接的解决方案?我TableViews完全用代码构建我,像这样:
UIViewController *tableViewController = [[TableViewController alloc] init];
navigationController = [[UINavigationController alloc]
initWithRootViewController:tableViewController];
[tableViewController release];
[window addSubview:navigationController.view];
Run Code Online (Sandbox Code Playgroud)
该窗口是我UIWindow在app delegate中的主要构建.从这里开始,我需要构建一些不同的TableViews(由控制navigationController),一些与fetchedResultsControllers自定义单元格等等.我更喜欢在代码中完全执行此操作,而不是使用nib,因为这会导致在代码和IB之间传播自定义,或者必须构建和维护6个以上的不同Nib.
我根本找不到一个工作示例,其中一个tableViewController类设置它自己的背景图像.如果我在其中一个TableViews(扩展UITableViewController)中执行此操作:
self.tableView.backgroundColor = backgroundColor;
Run Code Online (Sandbox Code Playgroud)
当然,我得到了tableView的背景颜色(这样也可以使细胞的颜色顺序着色,认为细胞从颜色中继承了它们的颜色tableView?)但是我希望有一个静态的背景图像,我的细胞可以上下滑动.不是用户手势上下滑动的"背景图像".正是GroupedStyle tableView提供的,但在PlainStyle tableView :) ..并使用代码完成,而不是IB.
我想我必须清除表格视图的背景颜色,然后在配置它们时设置单元格颜色,这样它们就不会透明.然后以某种方式"偷偷"从tableView实例里面的tableView视图下面隐藏一个背景图片?
我将如何解决这个问题,最好的解决方案是能够在viewDidLoad或我的TableViewController中的任何其他函数中执行此操作,以便将我的所有自定义保存在一个位置.
希望有人可以帮助我,我所有'谷歌搜索':)谢谢!
您需要将控制器设置为a UIViewController,而不是a UITableViewController.然后以tableview编程方式在背景上方添加imageView.
@interface SomeController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
...
UITableView *tableView;
...
}
@property (nonatomic, retain) UITableView *tableView;
@end
@implementation SomeController
@synthesize tableView;
...
- (void)loadView {
[super loadView];
UIImageView *v = [[[UIImageView alloc] initWithFrame:self.view.bounds] autorelease];
[v setImage:[UIImage imageNamed:@"table_background.png"]];
[self.view addSubview:v];
self.tableView = [[[UITableView alloc] initWithFrame:self.view.bounds] autorelease];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:self.tableView];
}
...
@end
Run Code Online (Sandbox Code Playgroud)
小智 6
如果你的目标是> iOS 3.2,你可以使用新的backgroundView属性直接设置UIImageView,例如:
// In your UITableViewController subclass
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background.png"]];
self.tableView.backgroundView = view;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17528 次 |
| 最近记录: |