我试图在我的 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
这里可能出了什么问题?