'UIWebview'에 해당되는 글 2건

  1. 2012.01.03 NSString replace
  2. 2011.11.01 UIWebView 관련.

NSString replace

Dev/iOS 2012. 1. 3. 00:57


UITextView 를 이용하여 입력 받은 문자열 안에 줄바꿈이 분명히 되어 있는데 UIWebView 에 출력을 하면 줄바꿈이 안된 상태로 출력이 되는게 아닌가...

생각 못한게 줄바꿈이 "\n" 으로 되어 있으므로 웹페이지에서는 줄바꿈이 안된다. 그래서 HTML 문으로 넣어주기 전에 "\n"을 "<br />"로 바꾸어 주어야 한다.

그리고 또하나 주의할 점 !
전에 C/C++에서 문자열 시쿼스를 생각하여 "\\n"으로 변환해 주면 안된다.

NSString * str = @"안녕하세요\n반갑습니다.";
str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@"<br />"];
 

'Dev > iOS' 카테고리의 다른 글

아이폰 Tab bar에 배경 이미지 넣기.  (0) 2012.01.03
UINavigationBar 에 배경 이미지 삽입.  (0) 2012.01.03
터치 이벤트가 호출이 안되는 경우.  (0) 2011.12.29
cocoa 초기 로딩 화면 관련.  (0) 2011.12.21
UIView 갱신  (0) 2011.12.20
:

UIWebView 관련.

Dev/iOS 2011. 11. 1. 17:56


HTML 문자열로 표시할때 gif 이미지 표시하는 방법.
NSString *html = [NSString stringWithFormat:@"<img src='https://t1.daumcdn.net/cfile/tistory/2220894C56E7540A35", [myData base64Value];
[myWebView loadHTMLString:html baseURL:nil]
* 테스트 안됐음.


HTML 문자열로 표시할때 이미지를 파일로 저장한 후 해당 경로를 이용하여 표시하는 방법.

- (NSString *)writeToFile:(UIImage *)image
{
    // Get the location of the Documents directory
    NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 
   NSString * imagePath = [paths objectAtIndex:0];
    NSString * filename = @"tempDiaryPicture.png";
 
   NSString * filepath = [NSString stringWithFormat:@"%@/%@", imagePath, filename];
    
    // Save the image
    NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
 
   [imageData writeToFile:filepath atomically:YES];
    
    return filepath;
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    Model * model = _getModel();
    NSString * html = [NSString stringWithFormat:
 
                      @"<center><img src=\"file://%@\" width=\"240\" height=\"240\" border=\"0\"></center>\n"
                       "<hr />",
                       [self writeToFile:image]];    // UIImage * image -> 데이터베이스나 라이브러리와 같은 곳에서 읽어온경우.
    [webView loadHTMLString:html
 
                    baseURL:nil];
    
 }
 

Base64 encoding options on the Mac and iPhone



stackoverflow : http://stackoverflow.com/questions/1527351/how-to-add-an-uiimage-in-mailcomposer-sheet-of-mfmailcomposeviewcontroller-in-ip
NSData+base64 by matt gallagher : http://cocoawithlove.com/2009/06/base64-encoding-options-on-mac-and.html 



간략하게 설명하면 다음과 같다.
1. matt gallagher 의 홈페이지에 가서 NSData_Base64.zip 파일을 다운로드 받아 프로젝트 폴더에 압축을 해제.
2. NSData+Base64.h, NSData+Base64.m 파일을 프로젝트에 추가한다.
3. 사용하고자 하는 파일에 .h 파일을 #import 한다.
4. 다음과 같이 UIImage파일을 NSData로 변환을 거쳐 NSString으로 변환하여 이미지를 표시한다.
 UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"];
 
//Convert the image into data
   
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)];
 
//Create a base64 string representation of the data using NSData+Base64
   
NSString *base64String = [imageData base64EncodedString];
 
//Add the encoded string to the emailBody string
 
//Don't forget the "<b>" tags are required, the "<p>" tags are optional
   
[emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='https://t1.daumcdn.net/cfile/tistory/233F704F56E7540A34",base64String]];




'Dev > iOS' 카테고리의 다른 글

gdb stack trace at 'putpkt: write failed' 해결방법  (0) 2011.11.11
NSLog 함수 이름 관련 매크로.  (0) 2011.11.04
UILabel 관련 내용.  (0) 2011.11.01
UITextView  (0) 2011.11.01
Table View 관련  (0) 2011.10.28
: