我正在尝试在我的iOS6通用应用程序中使用透明的UIToolbar作为UITextField的inputAccessoryView。
在iOS6 iphone上运行时,工具栏显示为透明但有顶部边框。这只发生在iOS6 iphone上。不在iOS6 ipad设备上,不在iOS6 ipad模拟器上,甚至不在iOS6 iPhone模拟器上。以下是设备和模拟器的截图...
这是我的代码......
// Transparent Toolbar.m
@implementation TransparentToolbar
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor clearColor] setFill];
CGContextFillRect(context, self.bounds);
}
@end
// ViewController.m
#import "ViewController.h"
#import "TransparentToolbar.h"
@interface ViewController () {
TransparentToolbar *_accessoryView;
}
@end
@implementation ViewController
@synthesize textField;
- (TransparentToolbar *)_accessoryView
{
if (!_accessoryView) {
_accessoryView = [[TransparentToolbar alloc] init];
[_accessoryView sizeToFit];
[_accessoryView setTranslucent:YES];
UIBarButtonItem *flexButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIButton *resignKeyboardButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
[resignKeyboardButton setFrame:CGRectMake(0, 0, 44, 44)];
[resignKeyboardButton setTitle:@"DONE" forState:UIControlStateNormal];
[resignKeyboardButton addTarget:self action:@selector(didTapResignKeyboardButton:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *resignKeyboardBarButton =[[UIBarButtonItem alloc] initWithCustomView:resignKeyboardButton];
NSArray *itemsArray = [NSArray arrayWithObjects:flexButton, resignKeyboardBarButton, nil];
[_accessoryView setItems:itemsArray];
}
return _accessoryView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[textField setInputAccessoryView:[self _accessoryView]];
}
- (void)didTapResignKeyboardButton:(UIBarButtonItem *)aButtonItem
{
[textField resignFirstResponder];
}
@end
这里可能出现什么问题?