Practice of Tmall's iOS Weibo Project (5) Weibo Custom Search box searchBar and iossearchbar

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.