我將一些按鈕添加到已有的NavigationController中。這兩個按鈕被添加到一個UIView,它被推到NavigationItem上。按鈕停止並重新加載UIWebView。我該如何解決Objective-C中的NavigationController和UIToolbar偏移問題?
alt text http://i42.tinypic.com/jr2sd5.jpg
問題是,有這麼正在看都看很醜陋輕微的偏移問題。我希望我可以將UIToolbar設置爲透明或清晰的背景,但這似乎不是一種選擇。似乎也無法使用負偏移。我已經有了顏色匹配,但是如果仔細觀察,會有1px或2px的高亮顯示,導致視覺不匹配,然後在底部產生輕微偏移。
下面的一些相關代碼(based on this,入站Google員工)。我有什麼選擇來解決這個問題?
// create a toolbar for the buttons
UIToolbar* toolbar = [[UIToolbar alloc]
initWithFrame:CGRectMake(0, 0, 100, 45)];
[toolbar setBarStyle: UIBarStyleDefault];
UIColor *colorForBar = [[UIColor alloc] initWithRed:.72 green:0 blue:0 alpha:0];
toolbar.tintColor = colorForBar;
[colorForBar release];
//[toolbar setTranslucent:YES];
// create an array for the buttons
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard reload button
UIBarButtonItem *reloadButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self
action:@selector(reload)];
reloadButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:reloadButton];
[reloadButton release];
// create a spacer between the buttons
UIBarButtonItem *spacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[buttons addObject:spacer];
[spacer release];
// create a standard delete button with the trash icon
UIBarButtonItem *stopButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemStop
target:self
action:@selector(stopLoading)];
stopButton.style = UIBarButtonItemStyleBordered;
[buttons addObject:stopButton];
[stopButton release];
// put the buttons in the toolbar and release them
[toolbar setItems:buttons animated:NO];
[buttons release];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];
更新:對齊通過以下@Jacob固定由建議。現在,如何解決突出顯示不匹配問題?
alt text http://i40.tinypic.com/21j7fwy.jpg
極好的解決了對齊問題。有關如何使斜角/突出顯示匹配的建議? – buley 2010-05-09 19:21:31
@editor,什麼突出顯示不匹配? – 2010-05-09 19:25:45
查看上面更新的圖像。在頂部有一個1px或2px的細白色高光線,一旦UIToolbar結束(在「PM」中的「M」中間),就會變成灰色,我希望它看起來像我的NavBar的其餘部分。這兩個酒吧風格的設置爲「默認」(UIBarStyleDefault)。 – buley 2010-05-09 19:33:32