![](/img/trans.png)
[英]IOS Navigation Bar in Master/Detail storyboard project is transparent on ipad but not on iphone
[英]Ios App for Ipad & Iphone different navigation bar items
我正在開發適用於iPad和iPhone的應用程序,我已經在導航欄中添加了多個條形項目,但我想添加不同的條形項目...在iPad的導航欄中我只想添加2個項目到權利,已經在運作。 但我還想在iPhone導航欄的左側添加2個其他按鈕。 但是通過我正在嘗試的方式,我得到了相同的導航欄,相同的項目,以及如何向導航欄添加不同項目的任何想法。
這是我的代碼:
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action: @selector(IpadReload:)];
UIImage *emailIcon = [UIImage imageNamed:@"emailicon.png"];
UIBarButtonItem *emailButton = [[UIBarButtonItem alloc] initWithImage:(emailIcon) style:UIBarButtonItemStylePlain target:self action:@selector(emailButtonTapped:)];
NSArray *rightButtonsArray = [[NSArray alloc] initWithObjects:refreshButton, emailButton, nil];
self.navigationItem.rightBarButtonItems = rightButtonsArray;
UIBarButtonItem *previousButton = [[UIBarButtonItem alloc] initWithTitle:@"Previous" style:UIBarButtonItemStylePlain target: self action: @selector(PreviousClicked:)];
UIImage *phoneIcon = [UIImage imageNamed:@"phoneicon.png"];
UIBarButtonItem *phoneButton = [[UIBarButtonItem alloc] initWithImage:(phoneIcon) style:UIBarButtonItemStylePlain target:self action:@selector(callPhone:)];
NSArray *leftButtonsArray = [[NSArray alloc] initWithObjects:previousButton, phoneButton, nil];
self.navigationItem.leftBarButtonItems = leftButtonsArray;
實際上,你需要使用當前設備的iOS內置枚舉而不是isEqualToString:
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// iPad
} else {
// iPhone or iPod Touch - Add your two items to the right here
}
區分iPhone和iPad的簡潔方法是:
BOOL iPad = [[UIDevice currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPad;
// your setup
UIImage *buttonIcon = [UIImage imageNamed:
iPad ? @"padIcon.png" : @"phoneIcon.png"];
首先要區分iPhone和iPad,並根據它添加導航欄項目NSString * deviceType = [UIDevice currentDevice] .model;
if([deviceType isEqualToString:@"iPhone"]){
//Add iPhone navigation items
}else if ([deviceType isEqualToString:@"iPhone"]){
//Add iPad navigation items
}else{
// ipod等的默認項目}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.