Class: UISearchBar

Inherits:
UIView show all

Overview

The UISearchBar class implements a text field control for text-based searches. The control provides a text field for entering text, a search button, a bookmark button, and a cancel button. The UISearchBar object does not actually perform any searches. You use a delegate, an object conforming to the UISearchBarDelegate protocol, to implement the actions when text is entered and buttons are clicked.

Instance Attribute Summary (collapse)

Attributes inherited from UIView

#alpha, #autoresizesSubviews, #autoresizingMask, #backgroundColor, #bounds, #center, #clearsContextBeforeDrawing, #clipsToBounds, #contentMode, #contentScaleFactor, #exclusiveTouch, #frame, #gestureRecognizers, #hidden, #layer, #multipleTouchEnabled, #opaque, #restorationIdentifier, #subviews, #superview, #tag, #transform, #userInteractionEnabled, #window

Attributes inherited from UIResponder

#inputView, #undoManager

Instance Method Summary (collapse)

Methods inherited from UIView

#addConstraint:, #addConstraints:, #addGestureRecognizer:, #addSubview:, #alignmentRectForFrame:, #alignmentRectInsets, animateWithDuration:animations:, animateWithDuration:animations:completion:, animateWithDuration:delay:options:animations:completion:, areAnimationsEnabled, beginAnimations:context:, #bringSubviewToFront:, commitAnimations, #constraints, #constraintsAffectingLayoutForAxis:, #contentCompressionResistancePriorityForAxis:, #contentHuggingPriorityForAxis:, #convertPoint:fromView:, #convertPoint:toView:, #convertRect:fromView:, #convertRect:toView:, #decodeRestorableStateWithCoder:, #didAddSubview:, #didMoveToSuperview, #didMoveToWindow, #drawRect:, #drawRect:forViewPrintFormatter:, #encodeRestorableStateWithCoder:, #endEditing:, #exchangeSubviewAtIndex:withSubviewAtIndex:, #exerciseAmbiguityInLayout, #frameForAlignmentRect:, #gestureRecognizerShouldBegin:, #hasAmbiguousLayout, #hitTest:withEvent:, #initWithFrame:, #insertSubview:aboveSubview:, #insertSubview:atIndex:, #insertSubview:belowSubview:, #intrinsicContentSize, #invalidateIntrinsicContentSize, #isDescendantOfView:, layerClass, #layoutIfNeeded, #layoutSubviews, #needsUpdateConstraints, #pointInside:withEvent:, #removeConstraint:, #removeConstraints:, #removeFromSuperview, #removeGestureRecognizer:, requiresConstraintBasedLayout, #sendSubviewToBack:, setAnimationBeginsFromCurrentState:, setAnimationCurve:, setAnimationDelay:, setAnimationDelegate:, setAnimationDidStopSelector:, setAnimationDuration:, setAnimationRepeatAutoreverses:, setAnimationRepeatCount:, setAnimationStartDate:, setAnimationTransition:forView:cache:, setAnimationWillStartSelector:, setAnimationsEnabled:, #setContentCompressionResistancePriority:forAxis:, #setContentHuggingPriority:forAxis:, #setNeedsDisplay, #setNeedsDisplayInRect:, #setNeedsLayout, #setNeedsUpdateConstraints, #setTranslatesAutoresizingMaskIntoConstraints:, #sizeThatFits:, #sizeToFit, #systemLayoutSizeFittingSize:, transitionFromView:toView:duration:options:completion:, transitionWithView:duration:options:animations:completion:, #translatesAutoresizingMaskIntoConstraints, #updateConstraints, #updateConstraintsIfNeeded, #viewForBaselineLayout, #viewPrintFormatter, #viewWithTag:, #willMoveToSuperview:, #willMoveToWindow:, #willRemoveSubview:

Methods inherited from UIResponder

#becomeFirstResponder, #canBecomeFirstResponder, #canPerformAction:withSender:, #canResignFirstResponder, #isFirstResponder, #motionBegan:withEvent:, #motionCancelled:withEvent:, #motionEnded:withEvent:, #nextResponder, #reloadInputViews, #remoteControlReceivedWithEvent:, #resignFirstResponder, #touchesBegan:withEvent:, #touchesCancelled:withEvent:, #touchesEnded:withEvent:, #touchesMoved:withEvent:

Methods inherited from NSObject

#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version

Constructor Details

This class inherits a constructor from NSObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class NSObject

Instance Attribute Details

- (UITextAutocapitalizationType) autocapitalizationType

The auto-capitalization style for the text object. This property determines at what times the Shift key is automatically pressed, thereby making the typed character a capital letter. The default value is UITextAutocapitalizationTypeNone.

- (UITextAutocorrectionType) autocorrectionType

The auto-correction style for the text object. This property determines whether auto-correction is enabled or disabled during typing. With auto-correction enabled, the text object tracks unknown words and suggests a replacement candidate to the user, replacing the typed text automatically unless the user explicitly overrides the action. The default value is UITextAutocorrectionTypeDefault, which for most input methods results in auto-correction being enabled.

- (UIImage) backgroundImage

The background image for the search bar. Images that are 1 point wide or stretchable images are stretched, otherwise the image is tiled.

Returns:

- (UIBarStyle) barStyle

The style that specifies the receiver’s appearance. See UIBarStyle for possible values. The default value is UIBarStyleDefault.

Returns:

  • (UIBarStyle)

- (Object) delegate

The search bar’s delegate object. The delegate should conform to the UISearchBarDelegate protocol. Set this property to further modify the behavior. The default value is nil.

Returns:

- (UIView) inputAccessoryView

A custom input accessory view for the keyboard of the search bar. The default value is nil. When non-nil, this property represents a custom input accessory view that will be placed onto the search bar’s system-supplied keyboard.

Returns:

- (UIKeyboardType) keyboardType

The keyboard style associated with the text object. Text objects can be targeted for specific types of input, such as plain text, email, numeric entry, and so on. The keyboard style identifies what keys are available on the keyboard and which ones appear by default.The default value is UIKeyboardTypeDefault.

Returns:

- (String) placeholder

The string that is displayed when there is no other text in the text field. The default value is nil.

Returns:

- (String) prompt

A single line of text displayed at the top of the search bar. The default value is nil.

Returns:

- (UIImage) scopeBarBackgroundImage

The background image for the scope bar. Images that are 1 point wide or stretchable images are stretched, otherwise the image is tiled.

Returns:

- (Array) scopeButtonTitles

An array of strings indicating the titles of the scope buttons. The order of the strings in the array indicates the order that the corresponding buttons will be displayed, from left to right. The index in the array corresponds to the index used in selectedScopeButtonIndex.

Returns:

- (UIOffset) searchFieldBackgroundPositionAdjustment

The offset of the search text field background in the search bar.

Returns:

- (Boolean) searchResultsButtonSelected

A Boolean value indicating whether the search results button is selected. The default value is NO.

Returns:

  • (Boolean)

- (UIOffset) searchTextPositionAdjustment

The offset of the text within the search text field background.

Returns:

- (Integer) selectedScopeButtonIndex

The index of the selected scope button. The indexes of the scope buttons are determined by the indexes of the strings in scopeButtonTitles.

Returns:

- (Boolean) showsBookmarkButton

A Boolean value indicating whether the bookmark button is displayed. The default value is NO.

Returns:

  • (Boolean)

- (Boolean) showsCancelButton

A Boolean value indicating whether the cancel button is displayed. The default value is NO.

Returns:

  • (Boolean)

- (Boolean) showsScopeBar

Specifies whether the scope bar is displayed.

Returns:

  • (Boolean)

- (Boolean) showsSearchResultsButton

A Boolean value indicating whether the search results button is displayed. The default value is NO.

Returns:

  • (Boolean)

- (UITextSpellCheckingType) spellCheckingType

The spell-checking type. The default value is UITextSpellCheckingTypeDefault.

- (String) text

The current or starting search text. The default value is nil.

Returns:

- (UIColor) tintColor

The color used to tint the bar. The bar style is ignored if this property is not nil. The default value is nil.

Returns:

- (Boolean) translucent

Specifies whether the receiver is translucent.

Returns:

  • (Boolean)

Instance Method Details

- (UIImage) imageForSearchBarIcon(icon, state:state)

Returns the image for a given search bar icon type and control state.

Parameters:

  • icon (UISearchBarIcon)

    An icon identifier constant.

  • state (UIControlState)

    A control state.Valid states are UIControlStateNormal and UIControlStateDisabled.

Returns:

  • (UIImage)

    The image used for the search bar icon identified by icon in the state identified by state.

- (UIOffset) positionAdjustmentForSearchBarIcon(icon)

Returns the position adjustment for a given icon. The offset is used to adjust the position of an icon within the search text field.

Parameters:

Returns:

  • (UIOffset)

    The position adjustment for the icon identified by icon.

- (UIImage) scopeBarButtonBackgroundImageForState(state)

Returns the background image for the scope bar button in a given state. If the background image is an image returned from stretchableImageWithLeftCapWidth:topCapHeight: (UIImage), the cap widths are calculated from that information, otherwise, the cap width is calculated by subtracting one from the image’s width then dividing by 2. The cap widths are used as the margins for text placement. To adjust the margin use the margin adjustment methods.

Parameters:

  • state (UIControlState)

    A control state.

Returns:

  • (UIImage)

    The background image for the scope bar button in state.

- (UIImage) scopeBarButtonDividerImageForLeftSegmentState(leftState, rightSegmentState:rightState)

Returns the divider image to use for a given combination of left and right segment states. For more details, see setScopeBarButtonDividerImage:forLeftSegmentState:rightSegmentState:

Parameters:

  • leftState (UIControlState)

    The state of the left segment for which to provide the divider image.The state may be UIControlStateNormal or UIControlStateSelected.

  • rightState (UIControlState)

    The state of the right segment for which to provide the divider image.The state may be UIControlStateNormal or UIControlStateSelected.

Returns:

  • (UIImage)

    The divider image to use for the combination of leftState and rightState.

- (Hash) scopeBarButtonTitleTextAttributesForState(state)

Returns the text attributes for the search bar’s button’s title string for a given state.

Parameters:

  • state (UIControlState)

    A control state.

Returns:

  • (Hash)

    The text attributes for the search bar’ button’s title string for state.The attributes may specify the font, text color, text shadow color, and text shadow offset, using the keys found in NSString UIKit Additions Reference.

- (UIImage) searchFieldBackgroundImageForState(state)

Returns the search text field image for a given state.

Parameters:

  • state (UIControlState)

    A control state.Valid states are UIControlStateNormal and UIControlStateDisabled.

Returns:

  • (UIImage)

    The search text field image image to use for state.

- (Object) setImage(iconImage, forSearchBarIcon:icon, state:state)

Sets the image for a given search bar icon type and control state.

Parameters:

  • iconImage (UIImage)

    The image to use for the search bar icon identified by icon in the state identified by state.

  • icon (UISearchBarIcon)

    An icon identifier constant.

  • state (UIControlState)

    A control state.Valid states are UIControlStateNormal and UIControlStateDisabled.

Returns:

- (Object) setPositionAdjustment(adjustment, forSearchBarIcon:icon)

Returns the position adjustment for a given icon. Use this method to adjust the position of an icon within the search text field.

Parameters:

  • adjustment (UIOffset)

    The offset to use for the icon identified by icon.

  • icon (UISearchBarIcon)

    An icon identifier constant.

Returns:

- (Object) setScopeBarButtonBackgroundImage(backgroundImage, forState:state)

Sets the background image for the scope bar button in a given state. For more details, see scopeBarButtonBackgroundImageForState:.

Parameters:

  • backgroundImage (UIImage)

    The background image for the scope bar button in state.

  • state (UIControlState)

    A control state.

Returns:

- (Object) setScopeBarButtonDividerImage(dividerImage, forLeftSegmentState:leftState, rightSegmentState:rightState)

Sets the divider image to use for a given combination of left and right segment states. To customize the segmented control appearance you need to provide divider images to go between two unselected segments (leftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal), selected on the left and unselected on the right (leftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal), and unselected on the left and selected on the right (leftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected).

Parameters:

  • dividerImage (UIImage)

    The divider image to use for the combination of leftState and rightState.

  • leftState (UIControlState)

    The state of the left segment for which to set the divider image.The state may be UIControlStateNormal or UIControlStateSelected.

  • rightState (UIControlState)

    The state of the right segment for which to set the divider image.The state may be UIControlStateNormal or UIControlStateSelected.

Returns:

- (Object) setScopeBarButtonTitleTextAttributes(attributes, forState:state)

Sets the text attributes for the search bar’ button’s title string for a given state.

Parameters:

  • attributes (Hash)

    A dictionary containing key-value pairs specifying the text attributes to use for state.You may specify the font, text color, text shadow color, and text shadow offset, using the keys found in NSString UIKit Additions Reference.

  • state (UIControlState)

    A control state.

Returns:

- (Object) setSearchFieldBackgroundImage(backgroundImage, forState:state)

Sets the search text field image for a given state.

Parameters:

  • backgroundImage (UIImage)

    The search text field image image to use for state.

  • state (UIControlState)

    A control state.Valid states are UIControlStateNormal and UIControlStateDisabled.

Returns:

- (Object) setShowsCancelButton(showsCancelButton, animated:animated)

Sets the display state of the cancel button optionally with animation.

Parameters:

  • showsCancelButton (Boolean)

    YES to display the cancel button, otherwise NO.

  • animated (Boolean)

    YES to use animation to change the display state of the cancel button, otherwise NO.

Returns: