views:

34

answers:

1

i want to add a button to toolbar of webview without using IB ,so i must do it using programmatically how to do it?

+1  A: 

I haven't tested this, but it should be close. It adds a button named "Stop" to the right side of a toolbar. You'd call this method from the viewDidLoad method of your view controller.

- (void)setUpToolbar
{
    UIBarButtonItem* flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                                                   target:nil
                                                                                   action:nil];

    UIBarButtonItem* stopButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Stop"
                                                                       style:UIBarButtonItemStylePlain
                                                                      target:self
                                                                      action:@selector(stopButtonAction:)];

    NSArray* items = [[NSArray alloc] initWithObjects:flexibleSpace, stopButtonItem, nil];
    [stopButtonItem release];
    [flexibleSpace release];
    [toolbar setItems:items animated:NO];
    [items release];
}

- (void)stopButtonAction:(id)sender
{
    // ... do something ...
}
Shaggy Frog
there is a predefined stop button for webview of identifier stop... i am asking about that one
lak in iphone
A `UIWebView` control does not contain a "stop button" by default. You're going to have to clarify exactly what you mean by the "predefined stop button".
Shaggy Frog