开发者

how to create a web view stop button programmatically

开发者 https://www.devze.com 2023-01-15 22:31 出处:网络
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

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 ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消