2

我在我的应用程序中为 TableView 的标题设置图像。

它在 Iphone 3Gs 中运行良好。但相同的代码在 Iphone 5 中不起作用。它仅显示具有非常小尺寸图像的框架。

当我增加帧宽度时,图像不会增加。

这是我的代码:

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        CGSize result = [[UIScreen mainScreen] bounds].size;
        NSLog(@"height%f",result.height);
        if(result.height > 500){
            NSLog(@"iPhone 5");

            UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320,30)];
            UIImageView *img = [[UIImageView alloc]initWithFrame:headerView.frame];
            if(tableView == tableview1)
                    {
                img.image = [UIImage imageNamed:@"My Contacts Overlay.fw.png"];
                    }
            else if(tableView == tableview2)
                    {
                img.image = [UIImage imageNamed:@"My Contacts Overlay2.fw.png"];
                    }

            [headerView addSubview:img];
            return headerView;
        }
}

任何人都可以请!帮帮我?

4

1 回答 1

0

为您的 headerView 和 img 设置 Autoresizingmask ...希望它会起作用

以编程方式自动调整掩码与 Interface Builder / xib / nib

于 2013-05-07T11:04:36.233 回答