UITableView 背景视图不适用于文本区域
我试图通过使用 UIImageView 设置 backgroundView 来自定义 UITableView 的外观,但无法正常工作,如图所示。 (仅适用于accessoryType并且位于文本之前的行的开头。)
任何人都可以帮我解决这个问题吗?
我的代码:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
NSDictionary *lineaAutobus = [buscamionService objectAtIndex:indexPath.row];
NSString *lineaAutobusNombre = [lineaAutobus objectForKey:@"nombre_lineaAutobus"];
[cell setBackgroundView:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tableViewCellBg.png"]] autorelease]];
cell.textLabel.text = lineaAutobusNombre;
return cell;
}
https://www.dropbox.com/s/ubok76ipshei931/Screen%20shot%202011-05-20%20at%206.25.29%20PM.png
I'm trying to customize how my UITableView looks by setting the backgroundView with an UIImageView, but is not working properly as you can see in the image. (only works for the accessoryType and at the start of the row before the text.)
Can anybody help me with this?
My code:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
NSDictionary *lineaAutobus = [buscamionService objectAtIndex:indexPath.row];
NSString *lineaAutobusNombre = [lineaAutobus objectForKey:@"nombre_lineaAutobus"];
[cell setBackgroundView:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tableViewCellBg.png"]] autorelease]];
cell.textLabel.text = lineaAutobusNombre;
return cell;
}
https://www.dropbox.com/s/ubok76ipshei931/Screen%20shot%202011-05-20%20at%206.25.29%20PM.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您需要将textLabel的backgroundColor设置为[UIColor clearColor]?
Perhaps you need to set the backgroundColor of the textLabel to [UIColor clearColor]?