Iphone 带有背景图像的TableView
我想在我的tableview后面有一个图像,我在后面添加了一个UIImage,并将tableview背景设置为clear,在IB中它显示了tableview后面的图像,但当我运行它时,我得到了一个黑色背景,有人能帮我吗 取下图像并将此代码添加到viewDidLoad:Iphone 带有背景图像的TableView,iphone,ios,uitableview,uiimage,Iphone,Ios,Uitableview,Uiimage,我想在我的tableview后面有一个图像,我在后面添加了一个UIImage,并将tableview背景设置为clear,在IB中它显示了tableview后面的图像,但当我运行它时,我得到了一个黑色背景,有人能帮我吗 取下图像并将此代码添加到viewDidLoad: UIView *patternView = [[UIView alloc] initWithFrame:self.tableView.frame]; patternView.backgroundColor = [UIColor c
UIView *patternView = [[UIView alloc] initWithFrame:self.tableView.frame];
patternView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
patternView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.backgroundView = patternView;
这是一种添加固定图像作为tableview背景的方法。或者,您可以通过在主控制器类中简单地分配tableview的backgroundView属性来实现,而无需子类化…请在
-(void)viewDidLoad
方法中尝试以下代码
self.tblView= [[UITableView alloc] initWithFrame:CGRectMake(17,110, 280.0, 265) style:UITableViewStyleGrouped];
self.tblView.delegate=self;
self.tblView.dataSource=self;
//self.tblView.backgroundColor=[UIColor clearColor];
self.tblView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img3.png"]];
[self.view addSubview:self.tblView];
是否要在tableview上滚动或固定背景?请确保已将委托和数据源连接到IBMOutlet中的tableview!另一个简短的问题是,我试图在IB中设置表视图的位置,但它不起作用,您知道如何通过编程实现这一点吗?