2012-10-08 4 views
5

하드 시트 된 HTML 페이지를 표시해야하는 양식 시트 세그가 있습니다. 지금은 두 부분으로 문제가 첫 번째 문제를 가지고 나는 그것이 작동하는 경우에 <left><CENTER> 태그를 변경할 수 있습니다UIWebView에서 HTML 컨텐트를 표시하는 방법 IOS

<CENTER><H1>A Simple Sample Web Page</H1><H4>By Frodo</H4> 
<H2>Demonstrating a few HTML features</H2></CENTER> 

enter image description here

같이 표시됩니다이지만 내 옵션을 제한합니다. 이 콘텐츠를 어떻게 표시 할 수 있습니까? 화면 중간에 정렬 문제가 있습니까?

질문의 두 번째 부분은 콘텐츠에 색상이나 링크를 어떻게 포함시킬 수 있습니까? 라인 ""FFFFFF">\n"에 나는 Expected ':' 라인에 라인의 "<a href="http://somegreatsite.com">\n" 절반 인 녹색이

내 전체 코드 같은 것입니다 엑스 코드에 의해 실행되지 않음을 의미 화면에 주석처럼 보인다 말한다 오류를 얻을 :

- (void) createWebViewWithHTML{ 
    //create the string 
    NSMutableString *html = [NSMutableString stringWithString: @"<html><head><title></title></head><body style=\"background:transparent;\">"]; 

    //continue building the string 
    [html appendString:@"<BODY BGCOLOR=" 
    ""FFFFFF">\n" 
    "<CENTER><IMG SRC="clouds.jpg" ALIGN="BOTTOM"> 
    "</CENTER> \n" 
    "<HR>\n" 
    "<a href="http://somegreatsite.com">\n" 
    "Link Name</a>\n" 

    "is a link to another nifty site\n" 

    "<H1>This is a Header</H1>\n" 

    "<H2>This is a Medium Header</H2>\n" 

    "Send me mail at <a href="mailto:[email protected]">\n" 

    "[email protected]</a>.\n" 

    "<P> This is a new paragraph!\n" 

    "<P> <B>This is a new paragraph!</B>\n" 

    "<BR> <B><I>This is a new sentence without a paragraph break, in bold italics.</I></B>\n" 

    "<HR>\n"]; 
    [html appendString:@"</body></html>"]; 

    //instantiate the web view 
    webView = [[UIWebView alloc] initWithFrame:self.view.frame]; 


    //make the background transparent 
    [webView setBackgroundColor:[UIColor clearColor]]; 

    //pass the string to the webview 
    [webView loadHTMLString:[html description] baseURL:nil]; 

    //add it to the subview 
    [self.view addSubview:webView]; 

} 

편집 : 추가 된 스토리 보드 사진 그래서

enter image description here

는 어떻게 올바른 alignm을 만들 수 있습니다 ent 및 색상/링크를 올바르게 삽입 하시겠습니까? 당신의 UIWebView 오른쪽 크기가있는 경우

+1

give webView = [[UIWebView alloc] initWithFrame : self.view. ** 경계 **]; 프레임 대신 – Charan

+0

그냥'html' 대신'[html description]' 이 필요한 이유는 무엇입니까? – DAS

+0

그게 당신이 문자열을 webview로 전달하는 방법이 아닐까요? –

답변

3
  1. 확인합니다. 그것은 화면보다 큰 것 같습니다.

  2. 장소 어떤 전에 \ 테스트 "

"하드 코딩 된 문자열에서 이 예.

에서

NSString *testString="This is a \"Test\""; 

결과 이것은이다 "

희망이 있습니다

+0

그것은 크기가 중요하지 않습니다 :), 그것은 그녀가 말한 것입니다 :) 나는 그것을 몇 번 바꿨지 만 그것은 Xcode에 의해 인식되지 않습니다. 질문에 추가 된 그림 –

+0

'webView = [[UIWebView alloc] initWithFrame : self.webView.frame];에 코드를 변경하고 \ 추가해 주셔서 감사합니다. –