2010-04-17 5 views
3

내 iPhone 응용 프로그램에 UIToolbar의 배경 이미지를 설정하고 싶습니다.iphone의 UIToolBar 배경 이미지 설정

현재 UIColorinitWithPatternImage:을 사용하여 설정하고 있습니다.

그러나 내가 원하는 것을하지 않습니다.

다른 해결책을 알려주세요.

+4

initWithPatternImage가 원하는 것을하지 않으면 원하는 것을 설명하면 어쩌면 답을 얻을 기회가 증가 할 것입니다. –

답변

3

또는 사용자 정의 클래스를 확인하고 (인터페이스 빌더를 통해) 컨트롤에 할당하고 그 내부의 drawRect 방법을 구현할 수 ...

- (void)drawRect:(CGRect)rect { 
    UIImage *image = [UIImage imageNamed: @"CustomImage.png"]; 
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
} 

등이
+0

네, 네비게이션 컨트롤러의 커스텀 스킨 네비게이션 바에도 사용할 수있는 숨겨진 숨겨진 기능입니다. –

4

사용자 지정 클래스를 만들 필요가 없습니다. 다음과 같이 UIToolBar에 카탈로그를 추가 할 수 있습니다.

@implementation UIToolbar (UIToolbarCategory) 
- (void)drawRect:(CGRect)rect { 
    UIColor *color = [UIColor colorWithRed:0.547 green:0.344 blue:0.118 alpha:1.000]; //whatever goes well with your background image. 
    UIImage *img = [UIImage imageNamed: @"your-navbar-img.png"]; 
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
    [img release]; 
    self.tintColor = color; 
    [super drawRect:rect]; 
} 
@end 

테스트를 마쳤으며 정상적으로 작동합니다.

추신 : 지난 밤에 4.3과 테스트했습니다. & 예상대로 작동하지 않았지만 4.2로 잘 작동합니다. 나는 어떤 이유도 찾지 못했고, 올바른 스 니펫을 발견하면 업데이트 할 것입니다.

4.3 이상의 경우 UIToolbar 또는 UINavigationBar 범주를 하위 클래스로 추가해야합니다. 제한은 당신은 당신이 당신의 XIB 파일의 모두가 개체마다 UIToolbar의에서는 CustomClass 을 변경해야이며, 다음과 같은 코드는 4.3

#import <UIKit/UIKit.h> 


@interface MyAppToolBar : UIToolbar{ 

} 

@end 

@implementation MyAppToolBar 

- (void)drawRect:(CGRect)rect { 
    [super drawRect:rect]; 
    UIColor *color = [UIColor colorWithRed:0.547 green:0.344 blue:0.118 alpha:1.000]; //wood tan color 
    UIImage *img = [UIImage imageNamed: @"your-navbar-img.png"]; 
    [img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
    [img release]; 
    self.tintColor = color; 

} 

@end 

의 문제를 작동합니다. 그리고 UIImagePickerController를 열어 앱 스타일에 맞게 탐색 바에 영향을 미치지 않을까 걱정됩니다.

+1

[super drawRect : rect]를 호출해야합니다. drawRect : 구현의 끝에서. – runmad

+0

감사합니다. @canada dev이 (가) 내 스 니펫을 업데이트했습니다. – palaniraja

+0

img에서 release를 호출하면 안됩니다 ... – nickfox