UIWebView背景图像框架

时间:2014-07-07 23:53:18

标签: ios uiwebview

这是我的代码

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    if ([[UIScreen mainScreen] bounds].size.height == 568) {
        webview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"tripadvisorwaiting5.png"]];
        CGRect frame = webview.frame;
        frame.size.width = 320;
        frame.size.height = 568;
        webview.frame = frame;
    }
    else {
        webview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"tripadvisorwaiting.png"]];
        CGRect frame = webview.frame;
        frame.size.width = 320;
        frame.size.height = 480;
        webview.frame = frame;
    }
}
else {
    webview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"tripadvisorwaitingipad.png"]];
    CGRect frame = webview.frame;
    frame.size.width = 768;
    frame.size.height = 1024;
    webview.frame = frame;
}

但是当页面加载时,图像太大或太小,并且根据设备不会缩放。 你能救我吗?

1 个答案:

答案 0 :(得分:0)

我相信+colorWithPatternImage会在您调用时将图片调整为框架大小,因此调用webview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"tripadvisorwaiting5.png"]];后调整框架大小对缩放图像没有影响。设置帧大小后尝试设置背景图像。例如:

if ([[UIScreen mainScreen] bounds].size.height == 568) {
    CGRect frame = webview.frame;
    frame.size.width = 320;
    frame.size.height = 568;
    webview.frame = frame;

    webview.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"tripadvisorwaiting5.png"]];
}