![](/img/trans.png)
[英]how to display the UIButton and UITableview in ios6&ios7 for 4-inches screen and 3.5 inches screen
[英]How to set the Background image for UITableview for ios7 3.5 inches and 4-inches screen
我正在開發適用於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];
}
首先 ,檢查項目包中是否存在dash-bord-bg-small.PNG
文件。
其次 ,請注意用打時UIImageView
對象,如果你這樣做-initWithImage:
和64PX指定64PX的圖像,然后將imageView
框架集等於圖像的尺寸。
稍后,如果您更改此的幀imageView
由320像素的對象,比如說,320像素,圖像仍然受到64PX 64PX而只有imageView
對象變大。 ( 無論如何...目前這對您來說不是一個大問題 )
最后 ...請注意,默認情況下,iOS6中的UITableViewCell
具有透明背景,但在iOS7中,背景為白色。
試試看,看看是否有幫助:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell.contentView setBackgroundColor:[UIColor clearColor]];
}
(可選) ...轉儲if-else塊,因為它是相同的*
嘗試這個
[weeklyTableview setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"dash-bord-bg-small.PNG"]]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.