Practice of Tmall's iOS Weibo Project (5) Weibo Custom Search box searchBar and iossearchbar
CAT/CAT sharing, must be excellent
For Original Articles, please reprint them. Reprinted Please note: Yan Nai-yu's blog
Address: http://blog.csdn.net/u013357243
I. Effect
Define a search box with UITextField
Ii. call:
The called code is very simple. You can simply use init and add the function yourself later.
-(Void) viewDidLoad {[super viewDidLoad]; // create the search box NYSearchBar * searchBar = [[NYSearchBar alloc] initWithFrame: CGRectMake (0, 0, [UIScreen mainScreen]. bounds. size. width, 35)]; searchBar. placeholder = @ "cat search"; // set titleView to self in the search box. navigationItem. titleView = searchBar ;}
Iii. Code:
NYSearchBar. m file content
There is nothing in the NYSearchBar. h file,
The idea is simple, that is, to put an image on the left, you can add other things on your own.
//// 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 = [super initWithFrame: frame]) {self. font = [UIFont systemFontOfSize: 13]; self. background = [UIImage placement: @ "searchbar_textfield_background"]; // set the view on the left. // initWithImage: the default UIImageView size is the same as the image size: [UIImage imageNamed: @ "searchbar_textfield_search_icon"]; // to empty the imageV set in the small block on the left. width + = 10; imageV. contentMode = UIViewContentModeCenter; self. leftView = imageV; // you must set the mode self for the Left view to display the view on the left of the search box. leftViewMode = UITextFieldViewModeAlways;} return self ;}@ end
We recommend a handsome iOS Learning Website: code4app
All kinds of iOS effects and source code are used as needed.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.