[英]UIBarButtonItem tintColor stopped working
由於某些原因,我無法在視圖上使用UINavigationBar,而是使用UIToolBar。 我正在使用帶有透明tintColor的虛擬左按鈕和帶有黑色tintColor的標題按鈕來正確居中標題並隱藏虛擬左欄按鈕,但是它不再起作用,並且虛擬左按鈕和標題按鈕都獲得了主要的tintColor或我禁用它們,它們變成灰色。
如何使它們理想地禁用為按鈕並設置適當的tintColor(透明和黑色)?
- (void)addToolbar
{
CGFloat barHeight = 44.0;
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(self.view.bounds.origin.x, self.view.bounds.size.width - barHeight, self.view.bounds.size.height, barHeight)];
UIBarButtonItem *flexibleSpaceButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
// Done button on the right
UIBarButtonItem *doneButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];
// dummy button on the left to have centered title
UIBarButtonItem *dummyButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:nil action:nil];
dummyButtonItem.enabled = NO;
dummyButtonItem.tintColor = [UIColor clearColor];
// title button
UIBarButtonItem *titleButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Title text here" style:UIBarButtonItemStylePlain target:nil action:nil];
titleButtonItem.enabled = NO;
titleButtonItem.tintColor = [UIColor blackColor];
// set toolbar items
toolbar.items = @[dummyButtonItem,flexibleSpaceButtonItem, titleButtonItem, flexibleSpaceButtonItem,doneButtonItem];
[self.view addSubview:toolbar];
}
為視圖指定色調時,該色調會自動傳播到視圖層次結構中的所有子視圖。 因為UIWindow繼承自UIView,所以您可以使用以下代碼通過設置窗口的tint屬性來為整個應用指定顏色:
在application:didFinishLaunchingWithOptions:
window.tintColor = [UIColor purpleColor];
源iOS過渡 。 在“ 使用色調顏色”部分中進行檢查
根據您的反饋,我發現通過在AppDelegate中執行以下操作:
self.window.tintColor = [UIColor colorWithRed:255/255.0 green:59/255.0 blue:48/255.0 alpha:1.0];
[[UITextField appearance] setTintColor:[UIColor colorWithRed:66/255.0 green:107/255.0 blue:242/255.0 alpha:1.0]];
第二行導致我的問題。 現在,我需要找出為什么將第二行放在這里:)。 謝謝你的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.