簡體   English   中英

在iOS 7中更改鍵盤上方的自定義UIToolbar的顏色(而不僅僅是更改文本顏色)

[英]Changing the Color of a custom UIToolbar above the keyboard (not just changing the text colour) in iOS 7

在我的應用程序中,我現在對以前使用輕型鍵盤的所有UITextField使用“深色”外觀的鍵盤。

在文本字段之一的鍵盤上方,我創建了一個自定義UIToolbar,其中包含一些按鈕,允許用戶選擇鍵盤上方的選項之一。

這似乎比需要的要難得多,但是我試圖使UIToolBar變暗而不是變亮,無論我如何嘗試,工具欄始終是白色的,我似乎只能更改按鈕的顏色。工具欄,而不是工具欄本身。

工具欄是用以下代碼創建的:

    UIToolbar *alertToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f,
                                                                          self.view.window.frame.size.width, 44.0f)];

    alertToolBar.backgroundColor = [UIColor blackColor];
    //alertToolBar.tintColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f];

    alertToolBar.translucent = NO;
    alertToolBar.items =  @[ [[UIBarButtonItem alloc] initWithTitle:@" GBP"
                                                              style:UIBarButtonItemStyleBordered
                                                             target:self
                                                             action:@selector(barButtonAddText:)],
                             [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                           target:nil
                                                                           action:nil],
                             [[UIBarButtonItem alloc] initWithTitle:@" USD"
                                                              style:UIBarButtonItemStyleBordered
                                                             target:self
                                                             action:@selector(barButtonAddText:)],
                             [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                           target:nil
                                                                           action:nil],
                             [[UIBarButtonItem alloc] initWithTitle:@" EUR"
                                                              style:UIBarButtonItemStyleBordered
                                                             target:self
                                                             action:@selector(barButtonAddText:)],
                             [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                           target:nil
                                                                           action:nil],

    self.itemTextField.inputAccessoryView = alertToolBar;

我已經使用上面注釋掉的代碼( //alertToolBar.tintColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f]; )進行了嘗試,並且條形圖始終保持白色,但這僅僅是改變顏色的“按鈕”。

如何將整個工具欄更改為黑色?

任何幫助,將不勝感激!

我猜您正在使用iOS 7.0 SDK,因此在這種情況下,barTint不再適用於此。

在這種情況下,您將需要使用barTintColor。

蘋果的文檔:

酒吧的tintColor行為在iOS 7.0上已更改。 它不再影響欄的背景,並且行為與添加到UIView的tintColor屬性相同。 要着色欄的背景,請使用-barTintColor。

在這種情況下應為:

alertToolBar.barTintColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f];

我想您要設置:

@property(nonatomic, retain) UIColor *barTintColor

暫無
暫無

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

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