I want to add two buttons of width 133 px a开发者_如何学Pythonnd 150 px each and 28 px in height on top of every view in my iPhone app. Only the view below this button bar will change, but when navigation occurs (push pop operation), I want this bar also to slide with the remaining view. basically, i want a bar containing 2 buttons to be present in ever screen of the app. Please help me. Thanks
You'd be best off writing a subclass of UIViewController (for instance call it CustomUIViewController
).
in the viewDidLoad method of this class you can add the view as appropriate eg:
- (void)viewDidLoad {
UIView *bar = [[[UIView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,28)] autorelease];
UIButton *buttonOne = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// etc...
[bar addSubview:buttonOne];
UIButton *buttonTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// etc...
[bar addSubview:buttonTwo];
[self.view insertSubview:bar atIndex:0];
}
That should work (as long as you remember to call [super viewDidLoad]
in all your classes.
Now you just have to make sure you're subclassing CustomUIViewController instead of UIViewController in your view controllers.
Edit
To get the navigation bar option to work do this:
UIBarButtonItem *cancel = [[[UIBarButtonItem alloc] initWithTitle:@"Cancelsdkjfnsdjfhksdjfhks" style:UIBarButtonItemStylePlain target:self action:@selector(cancel:)] autorelease];
[self.navigationItem setLeftBarButtonItem:cancel];
UIBarButtonItem *send = [[[UIBarButtonItem alloc] initWithTitle:@"Senddsfsdfsdfsdfsdfsdf" style:UIBarButtonItemStylePlain target:self action:@selector(send:)] autorelease];
[self.navigationItem setRightBarButtonItem:send];
self.navigationItem.titleView = [[[UIView alloc] init] autorelease];
We'll start by laying out a view containing buttons. In Xcode, create a new View-based iPhone application, and call it "GradientButtons" (or whatever you want). Double-click the GradientButtonsViewController.xib resource to open it in Interface Builder.
Drag a UIButton control from the library onto the view. Set its properties like this:
* Change the type to "Custom"
* Set the title to "Gray"
* Change the text color to white
* Change the background color to gray
精彩评论