AppleSearchBar - UBogun/Xojo-iosLib GitHub Wiki
Inherits from AppleView
Memory leak check: not yet done.
Status: complete
This is an implementation of UISearchBar, the iOS control for easy search requests. Core of the control is a textfield, but it features some additional views and methods:
Different search bar styles
Xojo integration
Usually you will not use the AppleSearchBar object for itself in your projects but rather the custom control iOSLibSearchBar. This features many convenience methods for handling the control with native xojo types and classes.
Constructor
Constructor (aRect As NSRect): Creates a new UISearchbar with the selected dimensions.
Properties
BackgroundImage As AppleImage: An image to paint the control's background with. 1pt wide or stretchable images are stretched, otherwise it is tiled to fill the control.
BarStyle As UIBarStyle: Choose between default and black bar style.
BarTintColor As AppleColor: Tint color for the search bar background. Translucent by default unless you set Translucent = False.
Placeholder As Text: The text that is shown when no user text was entered.
Prompt As Text: A single text line above the search bar.
ScopeBarBackgroundImage As AppleImage: Background image for the scope bar.
ScopeButtonTitles As AppleArray of CFStringRef: The button captions on the order they should appear.
SearchBarStyle As UISearchBarStyle: Three different display styles: Default; Prominent = translucent background,search field opaque; Minimal = no background, search field translucent.
SearchFieldBackgroundPositionAdjustment As UIOffset: The offset of the search text field background.
SearchResultsButtonSelected As Boolean: True if the search results button is selected.
SearchText As Text: The entered search text.
SearchTextPositionAdjustment As UIOffset: The offset of the text within the search text field background.
SelectedScopeButtonIndex As Integer: The index of the selected scope button.
ShowsBookmarkButton As Boolean: True to display the bookmark button.
ShowsCancelButton As Boolean: If true, displays a Cancel button right to the searchtextfield.
ShowsScopeBar As Boolean: Whether to display the scope bar.
ShowsSearchResultsButton As Boolean: Whether the bullet with an arrow down in the textfield is displayed.
TintColor As AppleColor: The color that is applied to key elements in the control.
Translucent As Boolean: Exactly that.
Methods
AnimateCancelButton (value as Boolean): Animates the cancel button to the value. Like the Set part of ShowsCancelButton but animated.
BackgroundImage (BarPosition As UIBarPosition, BarMetrics As UIBarMetrics) As AppleImage: Use like a property to get or set the backgroundimage for the search bar background in a certain barposition and metrics.
Image (Icon As UISearchBarIcon, State As UIControlState) As AppleImage: A virtual property to set and get the images to use for the search bar icon in a certain state, which means you can replace the standard icons with custom images.
PositionAdjustment (Icon As UISeachBarIcon) As UIOffset: Virtual property for the offset of a certain icon.
ScopeBarButtonDividerImage (LeftState, Rightstate As UIControlState) As AppleImage: Again a virtual property to set and get the divider images between different control states.
ScopeBarButtonTitleTextAttributes (State As UIControlState) As Apple(Mutable)Dictionary: A dictionary describing the font attributes for a certain state. You may specify the font, text color, text shadow color, and text shadow offset, using the keys found in NSString UIKit Additions Reference.
SearchFieldBackgroundImage (State As UIControlState) The background image of the search field for a certain state.
##Shared Property Appearance As AppleSearchBar (read-only): Change properties of this object to have them set on all searchfields in your app.
Events
The following events fire when a button on the searchfield was clicked:
BookmarkButtonClicked()
CancelButtonClicked()
ResultsListButtonsClicked()
SearchButtonClicked()
ScopeButtonSelectionChanged (ButtonIndex As Integer): Fires when the user tapped on a scope button.
TextDidBeginEditing(): The user started to edit the searchfield.
TextDidChange (SearchText As Text): That's the new content of the searchfield.
TextDidEndEditing(): Finished editing the searchfield.
Usually, you will not need the following events except for special cases where you want to influence the standard behavior of the SearchBar. Return true to inhibit standard functionality.
ShouldNotBeginEditing() As Boolean: The user wants to edit.
ShouldNotEndEditing() As Boolean: User wants to leave the searchfield.
TextShouldNotChange (Location As Integer, Length As Integer, NewText As Text) As Boolean: Tells you at what position and for how many characters the user wants to change the searchfieldtext (and into what).
Additionally, the full feature set of AppleView events is available, with the exception of DrawRect and LayoutSubviews.