Class: UISearchBar
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)
-
- autocapitalizationType
The auto-capitalization style for the text object.
-
- autocorrectionType
The auto-correction style for the text object.
-
- backgroundImage
The background image for the search bar.
-
- barStyle
The style that specifies the receiver’s appearance.
-
- delegate
The search bar’s delegate object.
-
- inputAccessoryView
A custom input accessory view for the keyboard of the search bar.
-
- keyboardType
The keyboard style associated with the text object.
-
- placeholder
The string that is displayed when there is no other text in the text field.
-
- prompt
A single line of text displayed at the top of the search bar.
-
- scopeBarBackgroundImage
The background image for the scope bar.
-
- scopeButtonTitles
An array of strings indicating the titles of the scope buttons.
-
- searchFieldBackgroundPositionAdjustment
The offset of the search text field background in the search bar.
-
- searchResultsButtonSelected
A Boolean value indicating whether the search results button is selected.
-
- searchTextPositionAdjustment
The offset of the text within the search text field background.
-
- selectedScopeButtonIndex
The index of the selected scope button.
-
- showsBookmarkButton
A Boolean value indicating whether the bookmark button is displayed.
-
- showsCancelButton
A Boolean value indicating whether the cancel button is displayed.
-
- showsScopeBar
Specifies whether the scope bar is displayed.
-
- showsSearchResultsButton
A Boolean value indicating whether the search results button is displayed.
-
- spellCheckingType
The spell-checking type.
-
- text
The current or starting search text.
-
- tintColor
The color used to tint the bar.
-
- translucent
Specifies whether the receiver is translucent.
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
Instance Method Summary (collapse)
-
- imageForSearchBarIcon:state:
Returns the image for a given search bar icon type and control state.
-
- positionAdjustmentForSearchBarIcon:
Returns the position adjustment for a given icon.
-
- scopeBarButtonBackgroundImageForState:
Returns the background image for the scope bar button in a given state.
-
- scopeBarButtonDividerImageForLeftSegmentState:rightSegmentState:
Returns the divider image to use for a given combination of left and right segment states.
-
- scopeBarButtonTitleTextAttributesForState:
Returns the text attributes for the search bar’s button’s title string for a given state.
-
- searchFieldBackgroundImageForState:
Returns the search text field image for a given state.
-
- setImage:forSearchBarIcon:state:
Sets the image for a given search bar icon type and control state.
-
- setPositionAdjustment:forSearchBarIcon:
Returns the position adjustment for a given icon.
-
- setScopeBarButtonBackgroundImage:forState:
Sets the background image for the scope bar button in a given state.
-
- setScopeBarButtonDividerImage:forLeftSegmentState:rightSegmentState:
Sets the divider image to use for a given combination of left and right segment states.
-
- setScopeBarButtonTitleTextAttributes:forState:
Sets the text attributes for the search bar’ button’s title string for a given state.
-
- setSearchFieldBackgroundImage:forState:
Sets the search text field image for a given state.
-
- setShowsCancelButton:animated:
Sets the display state of the cancel button optionally with animation.
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.
- (UIBarStyle) barStyle
The style that specifies the receiver’s appearance. See UIBarStyle for possible values. The default value is UIBarStyleDefault.
- (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.
- (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.
- (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.
- (String) placeholder
The string that is displayed when there is no other text in the text field. The default value is nil.
- (String) prompt
A single line of text displayed at the top of the search bar. The default value is nil.
- (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.
- (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.
- (UIOffset) searchFieldBackgroundPositionAdjustment
The offset of the search text field background in the search bar.
- (Boolean) searchResultsButtonSelected
A Boolean value indicating whether the search results button is selected. The default value is NO.
- (UIOffset) searchTextPositionAdjustment
The offset of the text within the search text field background.
- (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.
- (Boolean) showsBookmarkButton
A Boolean value indicating whether the bookmark button is displayed. The default value is NO.
- (Boolean) showsCancelButton
A Boolean value indicating whether the cancel button is displayed. The default value is NO.
- (Boolean) showsScopeBar
Specifies whether the scope bar is displayed.
- (Boolean) showsSearchResultsButton
A Boolean value indicating whether the search results button is displayed. The default value is NO.
- (UITextSpellCheckingType) spellCheckingType
The spell-checking type. The default value is UITextSpellCheckingTypeDefault.
- (String) text
The current or starting search text. The default value is nil.
- (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.
- (Boolean) translucent
Specifies whether the receiver is translucent.
Instance Method Details
- (UIImage) imageForSearchBarIcon(icon, state:state)
Returns the image for a given search bar icon type and control 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.
- (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.
- (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:
- (Hash) scopeBarButtonTitleTextAttributesForState(state)
Returns the text attributes for the search bar’s button’s title string for a given state.
- (UIImage) searchFieldBackgroundImageForState(state)
Returns the search text field image for a given state.
- (Object) setImage(iconImage, forSearchBarIcon:icon, state:state)
Sets the image for a given search bar icon type and control state.
- (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.
- (Object) setScopeBarButtonBackgroundImage(backgroundImage, forState:state)
Sets the background image for the scope bar button in a given state. For more details, see scopeBarButtonBackgroundImageForState:.
- (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).
- (Object) setScopeBarButtonTitleTextAttributes(attributes, forState:state)
Sets the text attributes for the search bar’ button’s title string for a given state.
- (Object) setSearchFieldBackgroundImage(backgroundImage, forState:state)
Sets the search text field image for a given state.
- (Object) setShowsCancelButton(showsCancelButton, animated:animated)
Sets the display state of the cancel button optionally with animation.