1、取消NSTextField选中时的蓝色背景
[self.searchField.cell setFocusRingType:NSFocusRingTypeNone];
2、NSTextField变为Focus状态时的回调
1)自定义一个继承自NSTextField的LYSearchField类,
LYSearchField.h:
#import@protocol LYSearchFieldDelegate@optional
- (void)searchFieldFocused;
@end
@interface LYSearchField : NSTextField
@end
LYSearchField.m:
#import "LYSearchField.h"
@implementation LYSearchField
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
// Drawing code here.
}
- (BOOL)becomeFirstResponder{
[super becomeFirstResponder];
[(id<LYSearchFieldDelegate>)self.delegate searchFieldFocused];
return YES;
}
@end
2)在要使用LYSearchField的类中遵守LYSearchFieldDelegate 实现 -(void)searchFieldFocused;
3、使用代码最小化窗口
[self.window performMiniaturize:nil];
4、让NSTableView不能水平滚动
[self.tableView sizeToFit];
5、让NSTextField 不再focus
[self.window makeFirstResponder:nil];
6.让NSTextField变成focus
[self.passField becomeFirstResponder];
网友评论