Cat and Cat share. Must boutique
Original article. Welcome reprint.
Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243
One: Effect
Simple definition of a search box with Uitextfield
Two: Call:
The code to invoke. Very easy, direct Init can, after adding the function of their own.
- (void)viewDidLoad { [super viewDidLoad]; // 创建搜索框 NYSearchBar *searchBar = [[NYSearchBar alloc] initWithFrame:CGRectMake(00, [UIScreen mainScreen].bounds.size.width35)]; searchBar.placeholder = @"猫猫搜索"; // 设置titleView为搜索框 self.navigationItem.titleView = searchBar;}
Three: Code:
NYSEARCHBAR.M File Contents
There is nothing in the NYSearchBar.h file,
The idea is very easy, is to put a picture on the left, you can add other things.
////NYSEARCHBAR.M//Cat Weibo////Created by Apple on 15-7-29.//Copyright (c) 2015 Znycat. All rights reserved.//#import "NYSearchBar.h" @implementation nysearchbar -(Instancetype) initWithFrame: (CGRect) frame{if( Self= [SuperInitwithframe:frame]) { Self. Font= [UifontSystemfontofsize: -]; Self. Background= [UIImageimagewithstretchablename:@"Searchbar_textfield_background"];//Set the view on the left ///Initwithimage: The default uiimageview is the same size as the picture Uiimageview*imagev = [[UiimageviewAlloc] initwithimage:[UIImageimagenamed:@"Searchbar_textfield_search_icon"]];//In order to empty out the left a small block setImagev. Width+=Ten; Imagev. Contentmode= Uiviewcontentmodecenter; Self. Leftview= Imagev;//Must be set. To display the view to the left of the search box, be sure to set the mode for the left view Self. Leftviewmode= Uitextfieldviewmodealways; }return Self;}@end
Recommend an iOS learning handsome site: Code4app
A wide variety of iOS effects and source code are used, with the accompanying.
Cat Learning iOS Weibo project Combat (5) Weibo define search box Searchbar