[英]How to set the Background image for UITableview for ios7 3.5 inches and 4-inches screen
I am working on ios application for iOS6 & iOS7 3.5 inches and 4-inches screen.I have some problem, when I set the background image for UITableview
.In iOS 6 4-inches and 3.5 inches screen the tableview background image displayed.There is no problem for displaying.But my iOS7 3.5 & 4-inches the tableview background image not displaying.That is my problem.This is my code. 我正在开发适用于iOS6和iOS7 3.5英寸和4英寸屏幕的ios应用程序。我为UITableview
设置背景图像时遇到了一些问题。在iOS 6 4英寸和3.5英寸屏幕中,显示了tableview背景图像。没问题,但是我的iOS7 3.5&4英寸的tableview背景图像没有显示,这是我的问题,这是我的代码。
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
weeklyTableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 60, 320, 480)];
weeklyTableview.dataSource=self;
weeklyTableview.delegate=self;
weeklyTableview.scrollEnabled=YES;
[self.view addSubview:weeklyTableview];
weeklyTableview.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
weeklyTableview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
tableBackgroundImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"dash-bord-bg-small.PNG"]];
tableBackgroundImage.frame=weeklyTableview.frame;
[weeklyTableview setBackgroundView:tableBackgroundImage];
}
else
{
weeklyTableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 60, 320, 480)];
weeklyTableview.dataSource=self;
weeklyTableview.delegate=self;
weeklyTableview.scrollEnabled=YES;
[self.view addSubview:weeklyTableview];
weeklyTableview.separatorStyle=UITableViewCellSeparatorStyleSingleLine;
weeklyTableview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin;
tableBackgroundImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"dash-bord-bg-small.PNG"]];
tableBackgroundImage.frame=weeklyTableview.frame;
[weeklyTableview setBackgroundView:tableBackgroundImage];
}
Firstly , check if the file dash-bord-bg-small.PNG
is present in the project bundle. 首先 ,检查项目包中是否存在dash-bord-bg-small.PNG
文件。
Secondly , please note that when playing with a UIImageView
object, if you do -initWithImage:
and specify an image of 64px by 64px, then the imageView
frame set is equal to the dimension of the image. 其次 ,请注意用打时UIImageView
对象,如果你这样做-initWithImage:
和64PX指定64PX的图像,然后将imageView
框架集等于图像的尺寸。
Later, if you change the frame of this imageView
object to, say, 320px by 320px, the image remains 64px by 64px while only the imageView
object has become larger. 稍后,如果您更改此的帧imageView
由320像素的对象,比如说,320像素,图像仍然受到64PX 64PX而只有imageView
对象变大。 ( Anyways... this isn't such a big issue for you at this moment ) ( 无论如何...目前这对您来说不是一个大问题 )
Lastly ... note that the UITableViewCell
in iOS6, by default, has a transparent background but in iOS7 it's background is white. 最后 ...请注意,默认情况下,iOS6中的UITableViewCell
具有透明背景,但在iOS7中,背景为白色。
Try this and see if it helps: 试试看,看看是否有帮助:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell.contentView setBackgroundColor:[UIColor clearColor]];
}
Optionally ... dump the if-else block since it's identical* (可选) ...转储if-else块,因为它是相同的*
尝试这个
[weeklyTableview setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"dash-bord-bg-small.PNG"]]];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.