2012-04-11 31 views
0

當您點擊iPhone上的webform時,這個藍色的「確定」按鈕在UIWebview中很常見。如何在UIWebview表單中創建鍵盤的OK按鈕?

The blue OK button

是否有一個簡單的方法來重新創建它的代碼?或者我將不得不以艱難的方式創造它?

最密切的代碼是:

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)]; 

但是是不一樣的......

回答

3

在Web視圖按鈕採用了半透明的UIToolbar以done按鈕樣式:

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]; 
+0

好主意!這是一個UIBarButtonItem :) – Rodrigo 2012-04-12 13:18:07

+0

關於「Anterior」/「Seguinte」(下一個,上一個)按鈕。只是一個UISegmentedControl或是一個UIBarButtonItem?我做了一件與此相同的事情,但不一樣。 – Rodrigo 2012-04-12 14:32:27

+0

這是一個包裹在UIBarButtonItem中的UISegmentedControl。我已更新我的文章中的代碼以包含它。 – Shaun 2012-04-13 20:54:26

相關問題