如何将图像和标题添加到表视图的标题IOS
答
在该方法中
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
你需要创建一个UIView
并添加其他视图一样UIImageView
(图像),UILabel
(为标题),最后返回UIView
。
答
- (UIView *)tableView : (UITableView *)tableView viewForHeaderInSection : (NSInteger) section {
UIImageView *imgVew = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]];
return imgVew;
}
通过这个,你可以设置图片为背景的tableview节头!
答
请使用此代码:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIImage *myImage = [UIImage imageNamed:@"loginHeader.png"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:myImage] autorelease];
imageView.frame = CGRectMake(10,10,300,100);
return imageView;
}
+0
不适合我。 100pt的高度不适用 – 2013-06-05 10:09:34
答
我用这个代码:
-(void)viewDidLoad
{
[super viewDidLoad];
self.tableView.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]];
}
+0
由于某种原因,我无法完成他的工作 – Shailesh 2015-12-27 15:12:59
答
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIImage * image = [UIImage imageNamed:@"logo-big.png"];
UIImageView * imgview = [[UIImageView alloc]initWithImage:image];
imgview.frame = CGRectMake(0, 0, 200, 200);
imgview.backgroundColor = [UIColor blackColor];
return imgview;
}
你指的是在的tableView或公共首标段的标头,TableView中 – tGilani 2012-08-06 07:03:04
头的顶部只有部分。 – Feroz 2012-08-06 07:09:48