how to create a web view stop button programmatically
i want to add开发者_JAVA技巧 a button to toolbar of webview without using IB ,so i must do it using programmatically how to do it?
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 ...
}
精彩评论