簡體   English   中英

UIBarButtonItem tintColor iOS4

[英]UIBarButtonItem tintColor iOS4

我正在使用以下代碼創建 UIBarButtonItem:

UIBarButtonItem* searchBarButton = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"search_picto"] style:UIBarButtonItemStyleBordered target:self action:@selector(actionSearch:)] autorelease];
searchBarButton.tintColor = [UIColor colorWithRed:0.27 green:0.60 blue:0.20 alpha:1.00];

我將此和另一個按鈕添加到 UIToolbar,不確定這是否相關。 這很好用,並給了我我想要的外觀:

UIButtonBarItem 截圖

問題是,在 iOS 4(我必須支持)中,我無法設置 tintColor。 無法識別的選擇器。 如何為 iOS 4 創建這樣的按鈕? 我需要能夠設置 tintColor 並擁有 UIBarButtonItemStyleBordered。

謝謝你的幫助。


我讓它像這樣工作:

UISegmentedControl* searchButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"", nil]];
[searchButton setImage:[UIImage imageNamed:@"search_picto"] forSegmentAtIndex:0];
searchButton.momentary = YES;
searchButton.segmentedControlStyle = UISegmentedControlStyleBar;
searchButton.tintColor = [DELEGATE.config getColor:IFXShopConfigScopeShop name:@"navigationTint"];
[searchButton addTarget:self action:@selector(actionSearch:) forControlEvents:UIControlEventValueChanged];

你必須用一個空的 NSString 初始化它,否則你不能設置圖像。 此外 addTarget 必須使用UIControlEventValueChanged

tintColor是在 iOS5 中添加的,對於 iOS4 在這里你有一個解決方案

您需要創建一個UIButton並自己繪制按鈕以使其看起來像這樣,或者使用此設置背景圖像並使用自定義視圖(您的UIButton )初始化UIBarButtonItem

PS 從 iOS6 發布開始,您不能再編譯到 armv6,並且您可以支持的最低版本是 4.3,據我所知,這不值得...

暫無
暫無

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

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