2013-08-09 1 views
0

NavigationBar에서 사용자 카르마를 표시하는 UIToolbar를 추가하려고합니다. 내가 가진 문제는 사진에서 볼 수 있듯이 색상이 정확히 같지 않다는 것입니다.UIToolbar와 NavigationBar에서 정확히 같은 색을 어떻게 표시합니까?

enter image description here

그래서, 어떤 아이디어는 어떻게이 문제를 해결할 수 있을까? 코드는 다음과 같습니다.

- (void)viewDidLoad 
{ 

[super viewDidLoad]; 
UIToolbar *tools = [[UIToolbar alloc] 
        initWithFrame:CGRectMake(0.0f, 0.0f, 80.0f, 45.00f)]; 

UILabel *karma = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, 0.0f, 40.0f, 44.00f)]; 
karma.text = [[NSUserDefaults standardUserDefaults] stringForKey:@"karma"]; 
karma.font = [UIFont fontWithName:@"Helvetica" size:(14.0)]; 
karma.textColor = [UIColor colorWithRed:(255.0) green:(255.0) blue:(255.0) alpha:1]; 
karma.backgroundColor = [UIColor colorWithRed:(64/255.0) green:(64/255.0) blue:(64/255.0) alpha:0]; 

UIImage *image = [UIImage imageNamed:@"ic_people.png"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
imageView.frame = CGRectMake(0.0f, 7.5f, 30.0f, 30.00f); 
// Add Pin button. 

[tools setBarStyle: UIBarStyleDefault]; 
[tools addSubview:karma]; 
[tools addSubview:imageView]; 

// Add toolbar to nav bar. 
UIBarButtonItem *karmaNav = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
self.navigationItem.rightBarButtonItem = karmaNav; 
... 

고맙습니다.

답변

1

UIToolbar 대신 UIView 내부에 카르마 라벨과 이미지를 삽입하지 않는 이유는 무엇입니까? 그런 다음 해당 UIView의 배경색을 clearColor로 설정할 수 있습니다. 이 같은

뭔가 :

UIView *tools = [[UIView alloc] 
        initWithFrame:CGRectMake(0.0f, 0.0f, 80.0f, 45.00f)]; 
tools.backgroundColor = [UIColor clearColor]; 

UILabel *karma = [[UILabel alloc] initWithFrame:CGRectMake(30.0f, 0.0f, 40.0f, 44.00f)]; 
karma.text = [[NSUserDefaults standardUserDefaults] stringForKey:@"karma"]; 
karma.font = [UIFont fontWithName:@"Helvetica" size:(14.0)]; 
karma.textColor = [UIColor colorWithRed:(255.0) green:(255.0) blue:(255.0) alpha:1]; 
karma.backgroundColor = [UIColor colorWithRed:(64/255.0) green:(64/255.0) blue:(64/255.0) alpha:0]; 

UIImage *image = [UIImage imageNamed:@"ic_people.png"]; 
UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; 
imageView.frame = CGRectMake(0.0f, 7.5f, 30.0f, 30.00f); 

[tools addSubview:karma]; 
[tools addSubview:imageView]; 

UIBarButtonItem *karmaNav = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
self.navigationItem.rightBarButtonItem = karmaNav; 
+0

그 해결책이었다 주셔서 감사합니다;)하지만 왜 UIToolbar에서 작동하지 않는 이유는 무엇입니까? – jaumevn

+0

UIToolbar 's는 당신이 원하는 것을 의미하지 않습니다. 기술적으로 UIToolbar를이 경우 사용할 수 있다고 생각하지만, UIView는이 상황에서 정확히 원하는 것입니다. UIToolbar [here] (http://developer.apple.com/library/ios/documentation/uikit/reference/UIToolbar_Class/Reference/Reference.html)와 UIView [here] (http : //)에 대한 연구를 할 수 있습니다. developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html). – hgwhittle

관련 문제