0

当您在 iPhone 上单击网络表单时,此蓝色“确定”按钮在 UIWebview 中很常见。

蓝色确定按钮

有没有一种简单的方法可以在代码中重新创建它?或者我将不得不以一种艰难的方式来创造它?

最接近的代码是:

    UISegmentedControl *buttonOK = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"OK"]];
    [buttonOK setSegmentedControlStyle:UISegmentedControlStyleBar];
    [buttonOK setTintColor:[UIColor colorWithRed:0.25f green:0.51f blue:0.95f alpha:1.0f]];
    [buttonOK setFrame:CGRectMake(276, 8, 38, 30)];

但是不一样吗...

4

1 回答 1

3

Web 视图中的按钮使用半透明 UIToolbar 和完成按钮样式:

UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Previous", @"Next", nil]];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.tintColor = [UIColor blackColor];
segmentedControl.momentary = YES;

UIBarButtonItem* segmentedControlItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithTitle:@"OK" style:UIBarButtonItemStyleDone target:self action:@selector(done:)];
UIBarButtonItem* flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
toolbar.barStyle = UIBarStyleBlack;
toolbar.translucent = YES;
toolbar.items = [NSArray arrayWithObjects:segmentedControlItem, flexSpace, item, nil];
[self.view addSubview:toolbar];
于 2012-04-11T21:07:12.577 回答