当您在iPhone上点击webform时,此蓝色“确定”按钮在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)];
但不一样......
答案 0 :(得分: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];