簡體   English   中英

如何在UIToolbar和NavigationBar中顯示完全相同的顏色?

[英]How do I show exactly the same color in UIToolbar and NavigationBar?

我正在嘗試添加一個UIToolbar,以在NavigationBar中顯示用戶業力。 我的問題是,顏色並不完全相等,如您在照片中所見。

在此處輸入圖片說明

那么,有什么主意我該如何解決呢? 這是代碼:

- (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;
...

謝謝。

為什么不將業力標簽和圖像嵌入UIView而不是UIToolbar中。 然后,您可以將該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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM