簡體   English   中英

如何在iPhone導航欄中移動標題

[英]how to move title over in iphone navigation bar

我希望可以給大家看一張照片,但是我在導航欄的右上方有兩個按鈕,在左側有一個刷新按鈕。 標題在中間,但是前兩個字母被右邊的按鈕之一覆蓋。

如何“推送”我的標題(或titleview-任一個),以便標題稍微移動一點? 我想將其向右移動約60像素。

下面的代碼做了我想要的-但是-由於某種原因,按鈕不起作用。 按鈕的代碼與我以前使用的代碼相同(以及以前可以工作的代碼),唯一的區別是它現在存儲在“工具”工具欄/數組中。

關於為什么我的按鈕現在被停用的任何想法?

// creating the two center buttons in the navigation bar
// create a toolbar to have two buttons in the right
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 0, 44.01)];

// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:5];


// create a non-bordered button (ends up looking like a title)
UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithTitle:@"Photos" style:UIBarButtonItemStylePlain   target:self action:NULL];
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL];
    [buttons addObject:bi];
[bi release];


// create a spacer
bi = [[UIBarButtonItem alloc]
      initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
[bi release];


// create another button with a camera icon
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(showPhotoPicker)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];


// create a spacer
bi = [[UIBarButtonItem alloc]
      initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
[bi release];


// create another button with 'your photos'
bi = [[UIBarButtonItem alloc] initWithTitle:@"your photos" style:UIBarButtonItemStyleBordered   target:self action:@selector(showUserGallery)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];

我認為您無法更改標題的框架。 意味着你只能破解; 1)在開始時添加一些空格。 2)將標題留空,並創建一個新標簽-將標簽放在navBar上。

希望能有所幫助,這就是我現在能想到的。 〜納塔納夫拉。

Miriam,也許以下代碼可以為您提供幫助。 在我的NavBarController的viewDidLoad內部,我正在使用它在NavBar中心的右側放一點圖像,而不是使用標准的“標題文本”。 而且“后退按鈕”對我來說一直很好。

UINavigationBar *navBar = [self navigationBar];
//inside the CGRectMake(), I can change the POSITION of my image, putting it anywhere.
UIView* imgContainer = [[UIView alloc] initWithFrame:CGRectMake(90, 10, 50, 80)];

UIImageView *imageView = (UIImageView *)[navBar viewWithTag:kSCNavBarImageTag];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"nav-bar-bg.png"]];
[imageView setTag:kSCNavBarImageTag];

[imgContainer addSubview:imageView];
[self.navigationBar addSubview:imgContainer];

UIColor *myColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
[navBar setTintColor:myColor];

[imageView release];

我認為您可以使用相同的方法:創建一個“ viewContainer”(在本例中為imageContainer)並將標題放在其中。 我沒有在您的情況下嘗試過,但也許可以。

希望對您有幫助。 問候。

暫無
暫無

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

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