-2
自定義UITextField:在單擊TextField輸入後,在keyborad彈出窗口後,輸入背景以再次進入前景,應用程序崩潰!來自enterBackground的UITextField enterForeground,應用程序崩潰
,如果你不點擊文本字段輸入,背景或前景的轉換,這是正常現象;部分代碼:
@implementatio BKSearchViewController
- (void)setNavgationView {
BKSearchBar *searchBar = [[BKSearchBar alloc] initWithFrame:CGRectMake(20, 27, kScreenWidth - 90, 30)];
searchBar.placeholder = @"輸入暱稱/拜託號";
searchBar.delegate = self;
[searchBar setKeyboardType:UIKeyboardTypeDefault];
[searchBar setReturnKeyType:UIReturnKeySearch];
[searchBar setPlaceholderColor:kcallColor(@"a4a4a4")];
[searchBar setPlaceholderFont:kFont(14)];
[searchBar addTarget:self action:@selector(SearchTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[navgationView addSubview:searchBar];
}
@end
//BKSearchBar The key code
@implementation BKSearchBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// 設置背景
self.backgroundColor = kcallColor(@"7d1d57");
self.returnKeyType = UIReturnKeySearch;
// 設置內容 -- 垂直居中
self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self UI];
}
return self;
}
- (void)UI{
// 設置左邊顯示一個放大鏡
UIImageView *leftView = [[UIImageView alloc] init];
omit...
//右邊的view
UIImageView *rightView = [[UIImageView alloc] init];
omit...
}
- (CGRect)placeholderRectForBounds:(CGRect)bounds{
CGRect rect = CGRectMake(self.leftView.right, (self.height - 24)/2, bounds.size.width, 14);
return rect;
}
- (void)clearText{
self.text = nil;
}
- (void)setPlaceholderColor:(UIColor *)color{
[self setValue:color forKeyPath:@"_placeholderLabel.textColor"];
}
- (void)setPlaceholderFont:(UIFont *)font{
[self setValue:font forKeyPath:@"_placeholderLabel.font"];
}
'背景或前景轉換'?不能得到你的問題,並顯示原始代碼不顯示任何圖像的代碼。 – vaibhav
不要發佈有關代碼的截圖,而是直接發佈代碼! – Lion
你有沒有實現UISearchBar委託?如果是,請發佈該代碼,以便我們可以瞭解發生了什麼問題。 – CodeChanger