2012-05-09 4 views
2

어떤 전화가 올 바릅니까? 두 호출이 같은 결과를 얻은 것 같습니다. 정확한에iOS : UIImage 초기화

UIImage *img = [UIImage imageNamed: @"image.png"]; 

답변

4

우선

UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]]; 

또는

UIImage *img = [[UIImage alloc] imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"]]; 
+2

+1 나는 두 번째를 잘못 읽었습니다 (이것은 현명한 일이 아닙니다) – MByD

-3

있는 UIImage가 초기화하는 쉬운 방법 ... imageWithContentsOfFile 클래스 사정 방법 (클래스 방법) 때문이다.

+3

'UIImage imageNamed'는 메모리 문제가 있으므로 피해야합니다. – Raptor

+0

질문의 답변이 아닙니까? – rishi

+0

@rishi 아니오, 컴파일하기 만한다고해서 반드시 작동한다는 의미는 아닙니다. –

관련 문제