我想重現像導航欄Tweetbot。
我仍在搜索是否可以在UINavigationBar
和之間放置UIButton
來代替標題,以使它完全適合左右按鈕,就像在Tweetbot應用程序中完成的那樣。
當我嘗試這樣做,過了一定規模的self.navigationItem.titleView
被調整下來自動像在TweetBot navigaton酒吧UIButton
告訴我,如果我錯過了什麼明顯的,
謝謝
我提供兩個截圖,讓你看看我米聊關於
我想重現像導航欄Tweetbot。
我仍在搜索是否可以在UINavigationBar
和之間放置UIButton
來代替標題,以使它完全適合左右按鈕,就像在Tweetbot應用程序中完成的那樣。
當我嘗試這樣做,過了一定規模的self.navigationItem.titleView
被調整下來自動像在TweetBot navigaton酒吧UIButton
告訴我,如果我錯過了什麼明顯的,
謝謝
我提供兩個截圖,讓你看看我米聊關於
他們可能已經推出自己的執行UINavigationBar
和/或UINavigationController
。我想這不值得嘗試破解UIKit,因爲它會非常脆弱,而且不會面向未來。
你可以添加一個按鈕到導航項的標題視圖屬性,該屬性接受一個UIView,並且因爲UIButton是UIView的子類,所以這不是問題。
或者,如果您正在使用故事板,只需將一個按鈕拖到導航欄的中心,就很容易。
// Create the button, and specify the type
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
// Set the button's frame
button.frame = CGRectMake(0.0f, 0.0f, 30.0f, 30.0f);
// Set your custom image for the button
[button setImage:[UIImage imageNamed:@"YOUR_IMAGE_NAME"] forState:UIControlStateNormal];
// Set the button's action, which is the method that will be called when it is pressed
[button addTarget:self action:@selector(doSomething:) forControlEvents:UIControlEventTouchUpInside];
// Add the button to the navigation bar's title view
[self.navigationItem.titleView addSubview:button];
你有沒有嘗試autoresizesSubviews設置爲YES上titleview的,然後設置在UIButton的正確自動尺寸口罩?如果這不起作用,我建議您創建自定義視圖子類並覆蓋-layoutSubviews以適應您的需求。
脆弱性和麪向未來的想法並不是我想到的。我仍然在尋找 – gsempe
我認爲你不需要走那麼遠。子類化這些類應該是最後的解決方案。 – nverinaud