å½ããã°ã®ã¢ã¯ã»ã¹ã解æãã¦ããã¨ããUIWebViewå ã®ç»é¢é·ç§»ãããã¯ããããããé²è¦§ããã¦ããããã§ããä»åãUIWebViewé¢é£ã§å°ãæ¸ãã¦ã¿ã¾ãã
æºå¸¯Webãã¼ã¸ããµã¼ãå´ã®å¤æ´ãªãiPhone/iPadã§èªã¿ããã表示ãããã¨ãããã¨ã¯ãããããã¨æãã¾ãã
æºå¸¯Webãã¼ã¸ã¨ããã®ã¯PCåããã¼ã¸ã«æ¯ã¹ã¬ã¤ã¢ã¦ããã·ã³ãã«ãªã®ã§ãå ´åã«ãã£ã¦ã¯åãå
容ã®PCåããã¼ã¸ãè¦ããããé²è¦§æ§ã¯è¯ãã£ããããã®ã§ããããããããæåãå°ãã表示ãããããè¨å®ããã¦ãããiPhoneã§è¦ãå ´åã«ã¯ãããããã¯ã«ãªãã¾ãã
UIWebViewã®æ©è½ãç¨ããã¨ãæºå¸¯Webãã¼ã¸ã®è¡¨ç¤ºãæ¹è¯ãããã¨ãã§ãã¾ããUIWebViewã¯ãWebãã¼ã¸ããã¼ããçµããã¨ãwebViewDidFinishLoad:ã¨ããããªã²ã¼ãã¡ã½ãããããªã²ã¼ãã«å¯¾ãã¦éã£ã¦ããã¾ãã
ããã«ãstringByEvaluatingJavaScriptFromString:ã¨ãããUIWebViewå ã®HTMLããã¥ã¡ã³ãã«å¯¾ãã¦JavaScriptãå®è¡ããã¡ã½ãããç¨æããã¦ããããã¾ãã
ã¤ã¾ãããã®äºã¤ã®ã¡ã½ãããç¨ããã¨ããã¼ã¸ããã¼ããçµãã£ã段éã§ãJavaScriptãå®è¡ãã¦ãã¹ã¿ã¤ã«ã·ã¼ããåçã«è¿½å ãããã¨ã§ãæºå¸¯Webåããã¼ã¸ã®ã¹ã¿ã¤ã«ãiPhoneã§è¦ãããããã«ãã¯ã©ã¤ã¢ã³ãå´ã§å¤æ´ãããã¨ãã§ãã¾ãã
- (void)webViewDidFinishLoad:(UIWebView *)webView { // JavaScriptãã¡ã¤ã«ãèªã¿è¾¼ã NSError* error; NSString* styleJsPath = [[NSBundle mainBundle] pathForResource:@"Style" ofType:@"js"]; NSString* js = [NSString stringWithContentsOfFile:styleJsPath encoding: NSUTF8StringEncoding error: &error]; // JavaScriptæååãè©ä¾¡ NSString* result = [webView stringByEvaluatingJavaScriptFromString:js]; }
JavaScriptã®ã³ã¼ãã¯ä¸è¨ã®éããä¸ã®ä¾ã§ã¯fontã¿ã°ã§æå®ãããæååãå¼·å¶çã«ï¼ï¼ptã«è¨å®ãã¾ãã
function style() { var styleNode = document.createElement("style"); var css = document.createTextNode( "font { font-size: 25pt;} " ); styleNode.appendChild( css ); var list = document.getElementsByTagName("head"); list[0].appendChild( styleNode ); } style();
ãã¡ãããæ¨ä»è©±é¡ã¨ãªããã¨ã®å¤ããã¬ã©ã±ã¼ç¹æã®åä½èå¥çªå·ã使ã£ãã¢ã¯ã»ã¹èªè¨¼ãç¨ãã¦ãããã¼ã¸ããªã©å®æã«è¡¨ç¤ºããªãããã«æ°ãã¤ãã¦ãã ããã