user1673099
user1673099

Reputation: 3289

Navigation title is not shown properly in iphone SDK

enter image description here

As you see my image, the Navigation title is under the two buttons.

The two left/right buttons are added subviews to navigation Bar. How can i set the navigation title width?? Eventhough it looks like ...

My code is as follow:

self.navigationItem.titleView.frame=CGRectMake(0, 0, 20, 40);
[[self navigationItem]setTitleView:bigLabel];

Upvotes: 0

Views: 318

Answers (3)

Nitin Gohel
Nitin Gohel

Reputation: 49720

If your UILable is too long you can set navigation bar Title like this way iniphone` but in ipad you can use same logic :-

enter image description here

 - (void)viewDidLoad
 {
       [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
       self.navigationItem.leftBarButtonItem = self.editButtonItem;

       UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)] autorelease];
       self.navigationItem.rightBarButtonItem = addButton;

       UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
       [label setBackgroundColor:[UIColor clearColor]];
       [label setNumberOfLines:0];
       [label setTextColor:[UIColor whiteColor]];
       [label setTextAlignment:UITextAlignmentCenter];
       [label setFont:[UIFont systemFontOfSize:12]];
       NSString    *str =@"1234567890 1234567890 1234567890 1234567890 1234567890 123456";
       [label setText:str];
       self.navigationItem.titleView = label;

 }

Hope its helps you .. :)

Upvotes: 1

mitesh trivedi
mitesh trivedi

Reputation: 15

Try to change the x position of the added subviews. Make that something like this:

Yoursubview.frame=CGRectMake(self.view.size.width-Yoursubview.frame.size.width,0,Yoursubview.frame.size.width,Yoursubview.frame.size.height);

Upvotes: 0

Ishu
Ishu

Reputation: 12787

Use Custom UIView with one button one switch and one title. Either make it by Xib or make it by code. And Hide default navigation bar.

Upvotes: 0

Related Questions