UISearchBar(QMUI)
@interface UISearchBar (QMUI)
提供更丰富的接口来修改 UISearchBar 的样式,注意大部分接口都同时支持配置表和 UIAppearance,如果有使用配置表并且该项的值不为 nil,则以配置表的值为准。
-
当以 tableHeaderView 的方式使用 UISearchBar 时,建议将这个属性置为 YES,从而可以帮你处理 https://github.com/Tencent/QMUI_iOS/issues/233 里列出的问题(抖动、iPhone X 适配等),默认为 NO
Declaration
Objective-C
@property (nonatomic) BOOL qmui_usedAsTableHeaderView;
Swift
var qmui_usedAsTableHeaderView: Bool { get set }
-
输入框内 placeholder 的颜色
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *qmui_placeholderColor;
Swift
var qmui_placeholderColor: UIColor? { get set }
-
输入框的文字颜色
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIColor *qmui_textColor;
Swift
var qmui_textColor: UIColor? { get set }
-
输入框的文字字体,会同时影响 placeholder 的字体
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIFont *qmui_font;
Swift
var qmui_font: UIFont? { get set }
-
输入框相对于系统原有布局位置的上下左右的偏移,正值表示向内缩小,负值表示向外扩大
Declaration
Objective-C
@property (nonatomic) UIEdgeInsets qmui_textFieldMargins;
Swift
var qmui_textFieldMargins: UIEdgeInsets { get set }
-
Undocumented
Declaration
Objective-C
@property(nullable, nonatomic, weak, readonly) UITextField *qmui_textField
Swift
weak var qmui_textField: UITextField? { get }
-
获取 searchBar 的背景 view,为一个 UIImageView 的子类 UISearchBarBackground,在 searchBar 初始化完即可被获取
Declaration
Objective-C
@property (nonatomic, weak, readonly, nullable) UIView *qmui_backgroundView;
Swift
weak var qmui_backgroundView: UIView? { get }
-
获取 searchBar 内的取消按钮,注意 UISearchBar 的取消按钮是在 setShowsCancelButton:animated: 被调用之后才会生成
Declaration
Objective-C
@property (nonatomic, weak, readonly, nullable) UIButton *qmui_cancelButton;
Swift
weak var qmui_cancelButton: UIButton? { get }
-
取消按钮的字体,由于系统的 cancelButton 是懒加载的,所以当不存在 cancelButton 时该值为 nil
Declaration
Objective-C
@property (nonatomic, strong, nullable) UIFont *qmui_cancelButtonFont;
Swift
var qmui_cancelButtonFont: UIFont? { get set }
-
获取 scopeBar 里的 UISegmentedControl
Declaration
Objective-C
@property (nonatomic, weak, readonly, nullable) UISegmentedControl *qmui_segmentedControl;
Swift
weak var qmui_segmentedControl: UISegmentedControl? { get }
-
修复当 UISearchController.searchBar 被当做 tableHeaderView 使用时可能产生的布局问题 https://github.com/Tencent/QMUI_iOS/issues/950
Declaration
Objective-C
@property (nonatomic) BOOL qmui_fixMaskViewLayoutBugAutomatically;
Swift
var qmui_fixMaskViewLayoutBugAutomatically: Bool { get set }
-
Undocumented
Declaration
Objective-C
- (void)qmui_styledAsQMUISearchBar;
Swift
func qmui_styledAsQMUISearchBar()
-
生成指定颜色的搜索框输入框背景图,大小与系统默认的保持一致,只是颜色不同
Declaration
Objective-C
+ (nullable UIImage *)qmui_generateTextFieldBackgroundImageWithColor: (nullable UIColor *)color;
Swift
class func qmui_generateTextFieldBackgroundImage(with color: UIColor?) -> UIImage?
-
生成指定背景色和底部边框颜色的搜索框背景图
Declaration
Objective-C
+ (nullable UIImage *) qmui_generateBackgroundImageWithColor:(nullable UIColor *)backgroundColor borderColor:(nullable UIColor *)borderColor;
Swift
class func qmui_generateBackgroundImage(with backgroundColor: UIColor?, borderColor: UIColor?) -> UIImage?