简体   繁体   English

如何为iOS7 3.5英寸和4英寸屏幕的UITableview设置背景图像

[英]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.

相关问题 如何在ios6和ios7中为4英寸屏幕和3.5英寸屏幕显示UIButton和UITableview - how to display the UIButton and UITableview in ios6&ios7 for 4-inches screen and 3.5 inches screen ios通用应用程序仅显示3.5英寸屏幕而不是4英寸屏幕 - ios universal app only show 3.5 inches screen instead of 4 inches screen 我怎样才能为iphone 3.5英寸屏幕和4英寸屏幕编写代码 - how can i write the code for iphone 3.5 inches screen and 4 inches screen 如何在ios7的uitableview单元格中设置背景图像? - how to set background image in uitableview cell in ios7? 在iOS Simulator 4和3.5英寸中加载新闻 - Loading news in both iOS Simulator 4 and 3.5 inches 如何在XCode 6中以3.5英寸和4英寸查看StoryBoard View - How to see StoryBoard View in 3.5 and 4 inches in XCode 6 在3,5英寸屏幕iOS上UIScrollView内部的UIView不能调整大小 - UIView inside UIScrollView not resizing on 3,5 inches screen iOS 我的打印按钮如何打印8.5英寸x 11英寸的图像? Swift 3,IOS - How can my print button print images that are 8.5 inches by 11 inches? Swift 3, IOS iOS 设备实际尺寸(以英寸为单位) - iOS device real size in inches 调整4 / 3.5英寸屏幕的UICollectionViewCells大小 - Adjust UICollectionViewCells Size for 4/3.5 inches screens
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM