1

次のコードを含む単純な html が 1 つあります。

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="English">
    <head>
        <link href="../Styles/design.css" rel="stylesheet" type="text/css" />
        <title>Image</title>
        <style type="text/css">
            @page 
            {
                margin: 0; 
                padding: 0; 
            }
        </style>
    </head>

    <body style="margin: 0; padding: 0; oeb-column-number: 1;">
        <div style="width: 100%; height: 100%; margin: 0; padding: 0; text-align: center;"><img alt="main" id="mainImage" src="../images/Image.jpg" style="height: 100%; max-width: 100%; max-height: 100%; padding: 0; margin: 0;" /></div>
    </body>
</html>

フォルダにImage.jpgファイル があります

Objective-C を使用して CSS ルールを追加し、imgタグの幅と高さを変更することは可能ですか? 私を助けてください。

このコードを試しましたが、うまくいきませんでした。

NSString *setImageRule = [NSString stringWithFormat:@"addCSSRule('img', 'max-width: %fpx; height: %fpx;')", self.webView.frame.size.width*0.75,self.webView.frame.size.height*0.75];
[webView stringByEvaluatingJavaScriptFromString:setImageRule];
4

1 に答える 1

1

UIImage のサイズを変更する場合は、画像が保存されているフォルダーにアクセスしてサイズを変更するだけです。たとえば、次のコードを使用します。

+ (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
    //UIGraphicsBeginImageContext(newSize);
    UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();    
    UIGraphicsEndImageContext();
    return newImage;
}
于 2013-06-03T09:00:16.470 に答える