Cat Learning iOS Weibo project Combat (5) Weibo define search box Searchbar

Source: Internet
Author: User

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

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.