Classes
The following classes are available globally.
-
这个控件是为了方便地实现那种类似设置界面的列表(每个 cell 的样式、内容、操作控件均不太一样,每个 cell 之间不复用),使用方式:
- 创建一个带 UITableView 的 viewController。
- 通过 init 或 initWithCellDataSections: 创建一个 dataSource。若通过 init 方法初始化,则请在 tableView 渲染前(viewDidLoad 或更早)手动设置一个 cellDataSections 数组。
- 将第 2 步里的 dataSource 赋值给 tableView.qmui_staticCellDataSource 即可完成一般情况下的界面展示。
- 若需要重写某些 UITableViewDataSource、UITableViewDelegate 方法,则在 viewController 里直接实现该方法,并在方法里调用 QMUIStaticTableViewCellDataSource (Manual) 提供的同名方法即可,具体可参考 QMUI Demo。
Declaration
Objective-C
@interface QMUIStaticTableViewCellDataSource : NSObject
Swift
class QMUIStaticTableViewCellDataSource : NSObject
-
一个 cellData 对象用于存储 static tableView(例如设置界面那种列表) 列表里的一行 cell 的基本信息,包括这个 cell 的 class、text、detailText、accessoryView 等。
See
QMUIStaticTableViewCellDataSourceDeclaration
Objective-C
@interface QMUIStaticTableViewCellData : NSObject
Swift
class QMUIStaticTableViewCellData : NSObject
-
QMUIToastView
是一个用来显示toast的控件,其主要结构包括:backgroundView
、contentView
,这两个view都是通过外部赋值获取,默认使用QMUIToastBackgroundView
和QMUIToastContentView
。拓展性:
QMUIToastBackgroundView
和QMUIToastContentView
是QMUI提供的默认的view,这两个view都可以通过appearance来修改样式,如果这两个view满足不了需求,那么也可以通过新建自定义的view来代替这两个view。另外,QMUI也提供了默认的toastAnimator来实现ToastView的显示和隐藏动画,如果需要重新定义一套动画,可以继承QMUIToastAnimator
并且实现QMUIToastAnimatorDelegate
中的协议就可以自定义自己的一套动画。样式自定义:建议通过 tintColor 统一修改整个 toastView 的内容样式。当然你也可以单独修改 contentView.tintColor。默认情况下 QMUIToastView.tintColor = UIColorWhite。
建议使用
QMUIToastView
的时候,再封装一层,具体可以参考QMUITips
这个类。See
QMUIToastBackgroundViewSee
QMUIToastContentViewSee
QMUIToastAnimatorSee
QMUITipsDeclaration
Objective-C
@interface QMUIToastView : UIView
Swift
class QMUIToastView : UIView
-
QMUIToastView
默认使用的contentView。其结构是:customView->textLabel->detailTextLabel等三个view依次往下排列。其中customView可以赋值任意的UIView或者自定义的view。 注意,customView 会响应 tintColor 的变化。而 textLabel/detailTextLabel 在没设置颜色到 attributes 里的情况下,也会跟随 tintColor 变化,设置了 attributes 的颜色则优先使用 attributes 里的颜色。@TODO: 增加多种类型的progressView的支持。
See moreDeclaration
Objective-C
@interface QMUIToastContentView : UIView
Swift
class QMUIToastContentView : UIView
-
See moreQMUIToastAnimator
可以让你通过实现一些协议来自定义ToastView显示和隐藏的动画。你可以继承QMUIToastAnimator
,然后实现QMUIToastAnimatorDelegate
中的方法,即可实现自定义的动画。QMUIToastAnimator默认也提供了几种type的动画:1、QMUIToastAnimationTypeFade;2、QMUIToastAnimationTypeZoom;3、QMUIToastAnimationTypeSlide;Declaration
Objective-C
@interface QMUIToastAnimator : NSObject <QMUIToastAnimatorDelegate>
Swift
class QMUIToastAnimator : NSObject, QMUIToastAnimatorDelegate
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIToastBackgroundView : UIView /** * 是否需要磨砂,默认NO。仅支持iOS8及以上版本。可以通过修改`styleColor`来控制磨砂的效果。 */ @property(nonatomic, assign) BOOL shouldBlurBackgroundView; @property(nullable, nonatomic, strong, readonly) QMUIVisualEffectView *effectView; /** * 如果不设置磨砂,则styleColor直接作为`QMUIToastBackgroundView`的backgroundColor;如果需要磨砂,则会新增加一个`UIVisualEffectView`放在`QMUIToastBackgroundView`上面。 */ @property(nullable, nonatomic, strong) UIColor *styleColor UI_APPEARANCE_SELECTOR; /** * 设置圆角。 */ @property(nonatomic, assign) CGFloat cornerRadius UI_APPEARANCE_SELECTOR; @end
Swift
class QMUIToastBackgroundView : UIView
-
QMUIAlertController的按钮,初始化完通过
See moreQMUIAlertController
的addAction:
方法添加到 AlertController 上即可。Declaration
Objective-C
@interface QMUIAlertAction : NSObject
Swift
class QMUIAlertAction : NSObject
-
See moreQMUIAlertController
是模仿系统UIAlertController
的控件,所以系统有的功能在QMUIAlertController里面基本都有。同时QMUIAlertController
还提供了一些扩展功能,例如:它的每个 button 都是开放出来的,可以对默认的按钮进行二次处理(比如加一个图片);可以通过 appearance 在 app 启动的时候修改整个QMUIAlertController
的主题样式。Declaration
Objective-C
@interface QMUIAlertController : UIViewController <QMUIModalPresentationComponentProtocol> { UIView *_containerView; UIView *_scrollWrapView; UIScrollView *_headerScrollView; UIScrollView *_buttonScrollView; UIControl *_maskView; }
Swift
class QMUIAlertController : UIViewController, QMUIModalPresentationComponentProtocol
-
一个提供通用的弹出浮层功能的控件,可以将任意
UIView
或UIViewController
以浮层的形式显示出来并自动布局。支持 3 种方式显示浮层:
推荐 新起一个
UIWindow
盖在当前界面上,将QMUIModalPresentationViewController
以rootViewController
的形式显示出来,可通过supportedOrientationMask
支持横竖屏,不支持在浮层不消失的情况下做界面切换(因为 window 会把背后的 controller 盖住,看不到界面切换)。 可通过 shownInWindowMode 属性来判断是否在用这种方式显示。[modalPresentationViewController showWithAnimated:YES completion:nil];
使用系统接口来显示,支持界面切换,注意 使用这种方法必定只能以动画的形式来显示浮层,无法以无动画的形式来显示,并且
animated
参数必须为NO
。可通过supportedOrientationMask
支持横竖屏。 可通过 shownInPresentedMode 属性来判断是否在用这种方式显示。[self presentViewController:modalPresentationViewController animated:NO completion:nil];
将浮层作为一个 subview 添加到
superview
上,从而能够实现在浮层不消失的情况下进行界面切换,但需要superview
自行管理浮层的大小和横竖屏旋转,而且QMUIModalPresentationViewController
不能用局部变量来保存,会在显示后被释放,需要自行 retain。横竖屏跟随当前界面的设置。 可通过 shownInSubviewMode 属性来判断是否在用这种方式显示。self.modalPresentationViewController.view.frame = CGRectMake(50, 50, 100, 100); [self.view addSubview:self.modalPresentationViewController.view];
默认的布局会将浮层居中显示,浮层的大小可通过接口控制:
- 如果是用
contentViewController
,则可通过preferredContentSizeInModalPresentationViewController:keyboardHeight:limitSize:
来设置 - 如果使用
contentView
,或者使用contentViewController
但没实现preferredContentSizeInModalPresentationViewController:keyboardHeight:limitSize:
,则调用contentView
的sizeThatFits:
方法获取大小。 - 浮层大小会受
maximumContentViewWidth
属性的限制,以及contentViewMargins
属性的影响。
通过
layoutBlock
、showingAnimation
、hidingAnimation
可设置自定义的布局、打开及隐藏的动画,并允许你适配键盘升起时的场景。默认提供背景遮罩
dimmingView
,你也可以使用自己的遮罩 view。默认提供多种显示动画,可通过
animationStyle
来设置。Warning
如果使用者retain了modalPresentationViewController,注意应该在
hideWithAnimated:completion:
里releaseSee
QMUIAlertController
See
QMUIDialogViewController
See
QMUIMoreOperationController
Declaration
Objective-C
@interface QMUIModalPresentationViewController : UIViewController
Swift
class QMUIModalPresentationViewController : UIViewController
-
专用于QMUIModalPresentationViewController的UIWindow,这样才能在
UIApplication.sharedApplication.windows
里方便地区分出来Declaration
Objective-C
@interface QMUIModalPresentationWindow : UIWindow
Swift
class QMUIModalPresentationWindow : UIWindow
-
通过业务定义的一个 key 来缓存 cell 的高度,需搭配 UITableView 使用,一般不用你自己去 init。 具体使用方式请看 UITableView (QMUICellHeightKeyCache) 的注释。
See moreDeclaration
Objective-C
@interface QMUICellHeightKeyCache : NSObject
Swift
class QMUICellHeightKeyCache : NSObject
-
一个常见的场景:当通过 objc_setAssociatedObject 以弱引用的方式(OBJC_ASSOCIATION_ASSIGN)绑定对象A时,假如对象A稍后被释放了,则通过 objc_getAssociatedObject 再次试图访问对象A时会导致野指针。 这时你可以将对象A包装为一个 QMUIWeakObjectContainer,并改为通过强引用方式(OBJC_ASSOCIATION_RETAIN_NONATOMIC/OBJC_ASSOCIATION_RETAIN)绑定这个 QMUIWeakObjectContainer,进而安全地获取原始对象A。
See moreDeclaration
Objective-C
@interface QMUIWeakObjectContainer : NSProxy
Swift
class QMUIWeakObjectContainer : NSProxy
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUISegmentedControl : UISegmentedControl /// 获取当前的所有 segmentItem,可能包括 NSString 或 UIImage。 @property(nonatomic, copy, readonly) NSArray *segmentItems; /** * 重新渲染 UISegmentedControl 的 UI,可以比较大程度地修改样式。比如 tintColor,selectedTextColor 等等。 * * @param tintColor Segmented 的 tintColor,作用范围包括字体颜色和按钮 border * @param selectedTextColor Segmented 选中状态的字体颜色 * @param fontSize Segmented 上字体的大小 */ - (void)updateSegmentedUIWithTintColor:(UIColor *)tintColor selectedTextColor:(UIColor *)selectedTextColor fontSize:(UIFont *)fontSize; /** * 用图片而非 tintColor 来渲染 UISegmentedControl 的 UI * * @param normalImage Segmented 非选中状态的背景图 * @param selectedImage Segmented 选中状态的背景图 * @param devideImage00 Segmented 在两个没有选中按钮 item 之间的分割线 * @param devideImage01 Segmented 在左边没选中右边选中两个 item 之间的分割线 * @param devideImage10 Segmented 在左边选中右边没选中两个 item 之间的分割线 * @param textColor Segmented 的字体颜色 * @param selectedTextColor Segmented 选中状态的字体颜色 * @param fontSize Segmented 的字体大小 */ - (void)setBackgroundWithNormalImage:(UIImage *)normalImage selectedImage:(UIImage *)selectedImage devideImage00:(UIImage *)devideImage00 devideImage01:(UIImage *)devideImage01 devideImage10:(UIImage *)devideImage10 textColor:(UIColor *)textColor selectedTextColor:(UIColor *)selectedTextColor fontSize:(UIFont *)fontSize; @end
Swift
class QMUISegmentedControl : UISegmentedControl
-
通过业务定义的一个 key 来缓存 cell 的 size,需搭配 UICollectionView 使用,一般不用你自己去 init。 具体使用方式请看 UICollectionView (QMUICellSizeKeyCache) 的注释。
See moreDeclaration
Objective-C
@interface QMUICellSizeKeyCache : NSObject
Swift
class QMUICellSizeKeyCache : NSObject
-
相册里某一个资源的包装对象,该资源可能是图片、视频等。
Note
QMUIAsset 重写了 isEqual: 方法,只要两个 QMUIAsset 的 identifier 相同,则认为是同一个对象,以方便在数组、字典等容器中对大量 QMUIAsset 进行遍历查找等操作。Declaration
Objective-C
@interface QMUIAsset : NSObject
Swift
class QMUIAsset : NSObject
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIAssetsGroup : NSObject - (instancetype)initWithPHCollection:(PHAssetCollection *)phAssetCollection; - (instancetype)initWithPHCollection:(PHAssetCollection *)phAssetCollection fetchAssetsOptions:(PHFetchOptions *)pHFetchOptions; /// 仅能通过 initWithPHCollection 和 initWithPHCollection:fetchAssetsOption 方法修改 phAssetCollection 的值 @property(nonatomic, strong, readonly) PHAssetCollection *phAssetCollection; /// 仅能通过 initWithPHCollection 和 initWithPHCollection:fetchAssetsOption 方法修改 phAssetCollection 后,产生一个对应的 PHAssetsFetchResults 保存到 phFetchResult 中 @property(nonatomic, strong, readonly) PHFetchResult *phFetchResult; /// 相册的名称 - (NSString *)name; /// 相册内的资源数量,包括视频、图片、音频(如果支持)这些类型的所有资源 - (NSInteger)numberOfAssets; /** * 相册的缩略图,即系统接口中的相册海报(Poster Image) * * @return 相册的缩略图 */ - (UIImage *)posterImageWithSize:(CGSize)size; /** * 枚举相册内所有的资源 * * @param albumSortType 相册内资源的排序方式,可以选择日期最新的排在最前面,也可以选择日期最新的排在最后面 * @param enumerationBlock 枚举相册内资源时调用的 block,参数 result 表示每次枚举时对应的资源。 * 枚举所有资源结束后,enumerationBlock 会被再调用一次,这时 result 的值为 nil。 * 可以以此作为判断枚举结束的标记 */ - (void)enumerateAssetsWithOptions:(QMUIAlbumSortType)albumSortType usingBlock:(void (^)(QMUIAsset *resultAsset))enumerationBlock; /** * 枚举相册内所有的资源,相册内资源按日期最新的排在最后面 * * @param enumerationBlock 枚举相册内资源时调用的 block,参数 result 表示每次枚举时对应的资源。 * 枚举所有资源结束后,enumerationBlock 会被再调用一次,这时 result 的值为 nil。 * 可以以此作为判断枚举结束的标记 */ - (void)enumerateAssetsUsingBlock:(void (^)(QMUIAsset *result))enumerationBlock; @end
Swift
class QMUIAssetsGroup : NSObject
-
构建 QMUIAssetsManager 这个对象并提供单例的调用方式主要出于下面两点考虑:
- 保存照片/视频的方法较为复杂,为了方便封装系统接口,同时灵活地扩展功能,需要有一个独立对象去管理这些方法。
- 使用 PhotoKit 获取图片,基本都需要一个 PHCachingImageManager 的实例,为了减少消耗, QMUIAssetsManager 单例内部也构建了一个 PHCachingImageManager,并且暴露给外面,方便获取 PHCachingImageManager 的实例。
Declaration
Objective-C
@interface QMUIAssetsManager : NSObject
Swift
class QMUIAssetsManager : NSObject
-
查看图片的控件,支持横向滚动、放大缩小、loading 及错误语展示,内部使用 UICollectionView 实现横向滚动及 cell 复用,因此与其他普通的 UICollectionView 一样,也可使用 reloadData、collectionViewLayout 等常用方法。
使用方式:
- 使用 initWithFrame: 或 init 方法初始化。
- 设置 delegate。
- 在 delegate 的 numberOfImagesInImagePreviewView: 方法里返回图片总数。
- 在 delegate 的 imagePreviewView:renderZoomImageView:atIndex: 方法里为 zoomImageView.image 设置图片,如果需要,也可调用 [zoomImageView showLoading] 等方法来显示 loading。
- 由于 QMUIImagePreviewViewDelegate 继承自 QMUIZoomImageViewDelegate,所以若需要响应单击、双击、长按事件,请实现 QMUIZoomImageViewDelegate 里的对应方法。
- 若需要从指定的某一张图片开始查看,可使用 currentImageIndex 属性。
See
QMUIImagePreviewViewControllerDeclaration
Objective-C
@interface QMUIImagePreviewView : UIView <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
Swift
class QMUIImagePreviewView : UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
-
支持缩放查看静态图片、live photo、视频的控件 默认显示完整图片或视频,可双击查看原始大小,再次双击查看放大后的大小,第三次双击恢复到初始大小。
支持通过修改 contentMode 来控制静态图片和 live photo 默认的显示模式,目前仅支持 UIViewContentModeCenter、UIViewContentModeScaleAspectFill、UIViewContentModeScaleAspectFit,默认为 UIViewContentModeCenter。注意这里的显示模式是基于 viewportRect 而言的而非整个 zoomImageView
See
viewportRectQMUIZoomImageView 提供最基础的图片预览和缩放功能以及 loading、错误等状态的展示支持,其他功能请通过继承来实现。
See moreDeclaration
Objective-C
@interface QMUIZoomImageView : UIView <UIScrollViewDelegate>
Swift
class QMUIZoomImageView : UIView, UIScrollViewDelegate
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIZoomImageViewVideoToolbar : UIView @property(nonatomic, strong, readonly) QMUIButton *playButton; @property(nonatomic, strong, readonly) QMUIButton *pauseButton; @property(nonatomic, strong, readonly) QMUISlider *slider; @property(nonatomic, strong, readonly) UILabel *sliderLeftLabel; @property(nonatomic, strong, readonly) UILabel *sliderRightLabel; // 可通过调整此属性来调整 toolbar 内部的间距,默认为 {0, 0, 0, 0} @property(nonatomic, assign) UIEdgeInsets paddings UI_APPEARANCE_SELECTOR; // 可通过这些属性修改 video 播放时屏幕底部工具栏的播放/暂停图标 @property(nonatomic, strong) UIImage *playButtonImage UI_APPEARANCE_SELECTOR; @property(nonatomic, strong) UIImage *pauseButtonImage UI_APPEARANCE_SELECTOR; @end
Swift
class QMUIZoomImageViewVideoToolbar : UIView
-
图片预览控件,主要功能由内部自带的 QMUIImagePreviewView 提供,由于以 viewController 的形式存在,所以适用于那种在单独界面里展示图片,或者需要从某张目标图片的位置以动画的形式放大进入预览界面的场景。
使用方式:
- 使用 init 方法初始化
- 添加 self.imagePreviewView 的 delegate
- 以 push 或 present 的方式打开界面。如果是 present,则支持 QMUIImagePreviewViewControllerTransitioningStyle 里定义的动画。特别地,如果使用 zoom 方式,则需要通过 sourceImageView() 返回一个原界面上的 view 以作为 present 动画的起点和 dismiss 动画的终点。
See
QMUIImagePreviewViewDeclaration
Objective-C
@interface QMUIImagePreviewViewController < UIViewControllerTransitioningDelegate>
Swift
class QMUIImagePreviewViewController : UIViewControllerTransitioningDelegate
-
负责处理 QMUIImagePreviewViewController 被 present/dismiss 时的动画,如果需要自定义动画效果,可按需修改 animationEnteringBlock、animationBlock、animationCompletionBlock。
See
QMUIImagePreviewViewController.transitioningAnimatorDeclaration
Objective-C
@interface QMUIImagePreviewViewTransitionAnimator : NSObject <UIViewControllerAnimatedTransitioning>
Swift
class QMUIImagePreviewViewTransitionAnimator : NSObject, UIViewControllerAnimatedTransitioning
-
Undocumented
Declaration
Objective-C
@interface QMUITestView : UIView @end
Swift
class QMUITestView : UIView
-
Undocumented
Declaration
Objective-C
@interface QMUITestWindow : UIWindow @end
Swift
class QMUITestWindow : UIWindow
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIAnimationHelper : NSObject typedef NS_ENUM(NSInteger, QMUIAnimationEasings) { QMUIAnimationEasingsLinear, QMUIAnimationEasingsEaseInSine, QMUIAnimationEasingsEaseOutSine, QMUIAnimationEasingsEaseInOutSine, QMUIAnimationEasingsEaseInQuad, QMUIAnimationEasingsEaseOutQuad, QMUIAnimationEasingsEaseInOutQuad, QMUIAnimationEasingsEaseInCubic, QMUIAnimationEasingsEaseOutCubic, QMUIAnimationEasingsEaseInOutCubic, QMUIAnimationEasingsEaseInQuart, QMUIAnimationEasingsEaseOutQuart, QMUIAnimationEasingsEaseInOutQuart, QMUIAnimationEasingsEaseInQuint, QMUIAnimationEasingsEaseOutQuint, QMUIAnimationEasingsEaseInOutQuint, QMUIAnimationEasingsEaseInExpo, QMUIAnimationEasingsEaseOutExpo, QMUIAnimationEasingsEaseInOutExpo, QMUIAnimationEasingsEaseInCirc, QMUIAnimationEasingsEaseOutCirc, QMUIAnimationEasingsEaseInOutCirc, QMUIAnimationEasingsEaseInBack, QMUIAnimationEasingsEaseOutBack, QMUIAnimationEasingsEaseInOutBack, QMUIAnimationEasingsEaseInElastic, QMUIAnimationEasingsEaseOutElastic, QMUIAnimationEasingsEaseInOutElastic, QMUIAnimationEasingsEaseInBounce, QMUIAnimationEasingsEaseOutBounce, QMUIAnimationEasingsEaseInOutBounce, QMUIAnimationEasingsSpring, // 自定义任意弹簧曲线 QMUIAnimationEasingsSpringKeyboard // 系统键盘动画曲线 }; /** * 动画插值器 * 根据给定的 easing 曲线,计算出初始值和结束值在当前的时间 time 对应的值。value 目前现在支持 NSNumber、UIColor 以及 NSValue 类型的 CGPoint、CGSize、CGRect、CGAffineTransform、UIEdgeInsets * @param fromValue 初始值 * @param toValue 结束值 * @param time 当前帧时间 * @param easing 曲线,见`QMUIAnimationEasings` */ + (id)interpolateFromValue:(id)fromValue toValue:(id)toValue time:(CGFloat)time easing:(QMUIAnimationEasings)easing; /** * 动画插值器,支持弹簧参数 * mass|damping|stiffness|initialVelocity 仅在 QMUIAnimationEasingsSpring 的时候才生效 */ + (id)interpolateSpringFromValue:(id)fromValue toValue:(id)toValue time:(CGFloat)time mass:(CGFloat)mass damping:(CGFloat)damping stiffness:(CGFloat)stiffness initialVelocity:(CGFloat)initialVelocity easing:(QMUIAnimationEasings)easing; @end
Swift
class QMUIAnimationHelper : NSObject
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIDisplayLinkAnimation : NSObject @property(nonatomic, strong, readonly) CADisplayLink *displayLink; @property(nonatomic, strong) id fromValue; @property(nonatomic, strong) id toValue; /// 动画时间 @property(nonatomic, assign) NSTimeInterval duration; /// 动画曲线 @property(nonatomic, assign) QMUIAnimationEasings easing; /// 是否需要重复,如果设置为YES,那么会无限重复动画,默认NO /// TODO: 目前功能上不支持小数点的循环次数,例如 0.5 1.5 @property(nonatomic, assign) BOOL repeat; /// 延迟开始动画 @property(nonatomic, assign) NSTimeInterval beginTime; /// 只有设置了repeat之后这个值才有用 @property(nonatomic, assign) float repeatCount; /// 只有设置了repeat之后这个值才有用。如果YES,则往前做动画之后自动往后做动画,默认NO @property(nonatomic, assign) BOOL autoreverses; /// 做动画的block,适用于只有一个属性需要做动画,curValue是经过计算后当前帧的值 @property(nonatomic, copy) void (^animation)(id curValue); /// 做动画的block,适用于多个属性做动画,需要在block里面自己计算当前帧的所有属性的值 @property(nonatomic, copy) void (^animations)(QMUIDisplayLinkAnimation *animation, CGFloat curTime); - (instancetype)initWithDuration:(NSTimeInterval)duration easing:(QMUIAnimationEasings)easing fromValue:(id)fromValue toValue:(id)toValue animation:(void (^)(id curValue))animation; - (instancetype)initWithDuration:(NSTimeInterval)duration easing:(QMUIAnimationEasings)easing animations:(void (^)(QMUIDisplayLinkAnimation *animation, CGFloat curTime))animations; /// 开始动画,无论是第一次做动画或者暂停之后再重新做动画,都调用这个方法 - (void)startAnimation; /// 停止动画,CADisplayLink 对象会被移出 - (void)stopAnimation; /// 即将开始做动画 @property(nonatomic, copy) void (^willStartAnimation)(void); /// 动画结束 @property(nonatomic, copy) void (^didStopAnimation)(void); @end
Swift
class QMUIDisplayLinkAnimation : NSObject
-
主题管理组件,可添加自定义的主题对象,并为每个对象指定一个专门的 identifier,当主题发生变化时,会遍历 UIViewController 和 UIView,调用每个 viewController 和每个可视 view 的 qmui_themeDidChangeByManager:identifier:theme: 方法,在里面由业务去自行根据当前主题设置不同的外观(color、image 等)。借助 QMUIThemeManagerCenter,可实现一个项目里同时存在多个维度的主题(例如全局维度存在 light/dark 2套主题,局部的某个界面存在 white/yellow/green/black 4套主题),各自互不影响,如果业务项目只需要一个维度的主题,则全都使用 QMUIThemeManagerCenter.defaultThemeManager 来获取 QMUIThemeManager 即可,如果业务有多维度主题的需求,可使用 +[QMUIThemeManagerCenter themeManagerWithName:] 生成不同的 QMUIThemeManager。
详细文档请查看 GitHub Wiki @link https://github.com/Tencent/QMUI_iOS/wiki/%E4%BD%BF%E7%94%A8-QMUITheme-%E5%AE%9E%E7%8E%B0%E6%8D%A2%E8%82%A4%E5%B9%B6%E9%80%82%E9%85%8D-iOS-13-Dark-Mode
关于 theme 的概念:
- 一个主题包含两个元素:identifier 表示主题的标志/名字,不允许重复;theme 代表主题对象本身,可以是任意的 NSObject 类型,只要业务自行规定即可。对于任意主题而言,identifier 和 theme 都不能为空,也不能重复。
- 主题的增删需要通过 QMUIThemeManager 的 addThemeIdentifier:theme:、removeThemeIdentifier:/removeTheme: 来实现。
- 可通过 QMUIThemeManager 的 themeIdentifiers、themes 属性来获取当前已注册的所有主题。
- 可通过修改 QMUIThemeManager 的 currentThemeIdentifier、currentTheme 属性来切换当前 App 的主题,修改这两个属性的其中一个属性,内部都会同时自动修改另外一个属性,以保证两者匹配。
关于 iOS 13 新增的 Dark Mode:
- 如果 App 只需要在 iOS 13 里才切换深色的主题,直接使用系统的方式去实现即可,无需用到 QMUIThemeManager 的任何功能,QMUIThemeManager 适用于 App 需要在全 iOS 版本里都支持相同的皮肤切换(也即 iOS 13 下系统的 Dark Mode 也只是被视为你业务的某个皮肤)。在 iOS 13 下,QMUIThemeManager 的作用只是帮你监听系统 Dark Mode 的切换,并将系统的样式转换成业务对应的主题名,后续的实际工作其实跟 iOS 12 下切换主题是一样的。
- 如果要令 QMUIThemeManager 自动响应 iOS 13 的 Dark Mode,请先为 identifierForTrait 赋值,在内部根据 trait.userInterfaceStyle 的值返回对应的主题 identifier,再把 respondsSystemStyleAutomatically 改为 YES 即可。
关于 App 界面响应主题变化的方式: 组件支持三种层面来响应主题变化:
- UIView 层面,如果是颜色(UIColor/CGColor)变化,请使用 [UIColor qmui_colorWithThemeProvider:] 方法来创建 UIColor,以及获取该 color 对应的 CGColor,建议每个颜色对应一个 @property,然后使用 [UIView qmui_registerThemeColorProperties:] 来注册这些需要在主题变化时自动刷新样式的 property,这样的好处是对设置颜色的时机没有要求,在 init 时就设置也没问题,不需要因为实现换肤而大量修改业务原有代码。如果是非 NSObject 的变化(例如 enum/struct 或者业务代码逻辑),可重写 [UIView qmui_themeDidChangeByManager:identifier:theme:],在里面根据当前主题做代码逻辑上的区分。
- UIViewController 层面,仅支持重写 [UIViewController qmui_themeDidChangeByManager:identifier:theme:] 方法来实现换肤。
- NSObject 层面,可通过监听 QMUIThemeDidChangeNotification 通知,在回调里处理主题切换事件(例如将当前选择的主题持久化记录下来,下次 App 启动直接应用)。
标准场景下的使用流程:
- App 启动时,按需初始化 theme 对象并注册到 QMUIThemeManager 里。
- 根据当前用户的选择记录(例如 NSUserDefaults),通过 currentThemeIdentifier/currentTheme 指定当前的主题。
- 对需要响应主题变化的界面,检查其中的所有 UIColor、CGColor 的代码,将颜色换成使用 [UIColor qmui_colorWithThemeProvider:] 创建,如果该颜色对应一个 property,则使用 [UIView qmui_registerThemeColorProperties:] 注册这个 property,如果不对应 property,则请在 qmui_themeDidChangeByManager:identifier:theme: 里重新设置该颜色。
- 通过 QMUIThemeDidChangeNotification 监听主题的变化,将其持久化存储以便下次启动时应用。
- 若需要响应 iOS 13 的 Dark Mode,参考 respondsSystemStyleAutomatically、identifierForTrait 的注释。
Declaration
Objective-C
@interface QMUIThemeManager : NSObject
Swift
class QMUIThemeManager : NSObject
-
用于获取 QMUIThemeManager,具体使用请查看 QMUIThemeManager 的注释。
See moreDeclaration
Objective-C
@interface QMUIThemeManagerCenter : NSObject
Swift
class QMUIThemeManagerCenter : NSObject
-
Warning
由于支持 NSCopying,增加属性时必须在 copyWithZone: 里复制一次Declaration
Objective-C
@interface QMUIThemeColor : UIColor
Swift
class QMUIThemeColor : UIColor
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIThemeImage : UIImage <QMUIDynamicImageProtocol, NSCopying> @property(nonatomic, copy) NSObject<NSCopying> *managerName; @property(nonatomic, copy) UIImage *(^themeProvider)(__kindof QMUIThemeManager * _Nonnull manager, __kindof NSObject<NSCopying> * _Nullable identifier, __kindof NSObject * _Nullable theme); @end
Swift
class QMUIThemeImage : UIImage, QMUIDynamicImageProtocol, NSCopying
-
Warning
由于支持 NSCopying,增加属性时必须在 copyWithZone: 里复制一次Declaration
Objective-C
@interface QMUIThemeVisualEffect : NSObject <QMUIDynamicEffectProtocol>
Swift
class QMUIThemeVisualEffect : NSObject, QMUIDynamicEffectProtocol
-
带箭头的小tips浮层,自带 imageView 和 textLabel,可展示简单的图文信息,支持 UIViewContentModeTop/UIViewContentModeBottom/UIViewContentModeCenter 三种布局方式。 QMUIPopupContainerView 支持以两种方式显示在界面上:
- 添加到某个 UIView 上(适合于 viewController 切换时浮层跟着一起切换的场景),这种场景只能手动隐藏浮层。
- 在 QMUIPopupContainerView 自带的 UIWindow 里显示(适合于用完就消失的场景,不要涉及界面切换),这种场景支持点击空白地方自动隐藏浮层。
使用步骤:
- 调用 init 方法初始化。
- 选择一种显示方式: 2.1 如果要添加到某个 UIView 上,则先设置浮层 hidden = YES,然后调用 addSubview: 把浮层添加到目标 UIView 上。 2.2 如果是轻量的场景用完即走,则 init 完浮层即可,无需设置 hidden,也无需调用 addSubview:,在后面第 4 步里会自动把浮层添加到 UIWindow 上显示出来。
- 通过为 sourceBarItem/sourceView/sourceRect 三者中的一个赋值,来决定浮层布局的位置。
- 调用 showWithAnimated: 或 showWithAnimated:completion: 显示浮层。
- 调用 hideWithAnimated: 或 hideWithAnimated:completion: 隐藏浮层。
Warning
如果使用方法 2.2,并且没有打开 automaticallyHidesWhenUserTap 属性,则记得在适当的时机(例如 viewWillDisappear:)隐藏浮层。如果默认功能无法满足需求,可继承它重写一个子类,继承要点:
- 初始化时要做的事情请放在 didInitialize 里。
- 所有 subviews 请加到 contentView 上。
- 通过重写 sizeThatFitsInContentView:,在里面返回当前 subviews 的大小。
- 在 layoutSubviews: 里,所有 subviews 请相对于 contentView 布局。
Declaration
Objective-C
@interface QMUIPopupContainerView : UIControl { CAShapeLayer *_backgroundLayer; CGFloat _arrowMinX; CGFloat _arrowMinY; }
Swift
class QMUIPopupContainerView : UIControl
-
每一条 QMUILog 日志都以 QMUILogItem 的形式包装起来
See moreDeclaration
Objective-C
@interface QMUILogItem : NSObject
Swift
class QMUILogItem : NSObject
-
log.name 的管理器,由它来管理每一个 name 是否可用、以及清理不需要的 name
See moreDeclaration
Objective-C
@interface QMUILogNameManager : NSObject
Swift
class QMUILogNameManager : NSObject
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUILogger : NSObject @property(nullable, nonatomic, weak) id<QMUILoggerDelegate> delegate; @property(nonnull, nonatomic, strong) QMUILogNameManager *logNameManager; + (nonnull instancetype)sharedInstance; - (void)printLogWithFile:(nullable const char *)file line:(int)line func:(nonnull const char *)func logItem:(nullable QMUILogItem *)logItem; @end
Swift
class QMUILogger : NSObject
-
做类似 CSS 里的 float:left 的布局,自行使用 addSubview: 将子 View 添加进来即可。
支持通过
See morecontentMode
属性修改子 View 的对齐方式,目前仅支持UIViewContentModeLeft
和UIViewContentModeRight
,默认为UIViewContentModeLeft
。Declaration
Objective-C
@interface QMUIFloatLayoutView : UIView
Swift
class QMUIFloatLayoutView : UIView
-
存放多个 delegate 指针的容器,必须搭配其他控件使用,一般不需要你自己 init。作用是让某个 class 支持同时存在多个 delegate。更多说明请查看 NSObject (QMUIMultipleDelegates) 的注释。
See moreDeclaration
Objective-C
@interface QMUIMultipleDelegates : NSObject
Swift
class QMUIMultipleDelegates : NSObject
-
支持的特性包括:
- 自定义 placeholderColor。
- 自定义 UITextField 的文字 padding。
- 支持限制输入的文字的长度。
- 修复 iOS 10 之后 UITextField 输入中文超过文本框宽度后再删除,文字往下掉的 bug。
Declaration
Objective-C
@interface QMUITextField : UITextField
Swift
class QMUITextField : UITextField
-
提供以下功能:
- 支持让文字和图片自动跟随 tintColor 变化(系统的 UIButton 默认是不响应 tintColor 的)
- highlighted、disabled 状态均通过改变整个按钮的alpha来表现,无需分别设置不同 state 下的 titleColor、image。alpha 的值可在配置表里修改 ButtonHighlightedAlpha、ButtonDisabledAlpha。
- 支持点击时改变背景色颜色(highlightedBackgroundColor)
- 支持点击时改变边框颜色(highlightedBorderColor)
- 支持设置图片相对于 titleLabel 的位置(imagePosition)
- 支持设置图片和 titleLabel 之间的间距,无需自行调整 titleEdgeInests、imageEdgeInsets(spacingBetweenImageAndTitle)
Warning
QMUIButton 重新定义了 UIButton.titleEdgeInests、imageEdgeInsets、contentEdgeInsets 这三者的布局逻辑,sizeThatFits: 里会把 titleEdgeInests 和 imageEdgeInsets 也考虑在内(UIButton 不会),以使这三个接口的使用更符合直觉。Declaration
Objective-C
@interface QMUIButton : UIButton
Swift
class QMUIButton : UIButton
-
QMUIFillButton 实心填充颜色的按钮,支持预定义的几个色值
See moreDeclaration
Objective-C
@interface QMUIFillButton : QMUIButton
Swift
class QMUIFillButton : QMUIButton
-
支持显示下划线的按钮,可用于需要链接的场景。下划线默认和按钮宽度一样,可通过
See moreunderlineInsets
调整。Declaration
Objective-C
@interface QMUILinkButton : QMUIButton
Swift
class QMUILinkButton : QMUIButton
-
“幽灵”按钮,也即背景透明、带圆角边框的按钮
可通过
QMUIGhostButtonColor
设置几种预设的颜色,也可以用ghostColor
设置自定义颜色。Warning
默认情况下,ghostColor
只会修改文字和边框的颜色,如果需要让 image 也跟随ghostColor
的颜色,则可将adjustsImageWithGhostColor
设为YES
Declaration
Objective-C
@interface QMUIGhostButton : QMUIButton
Swift
class QMUIGhostButton : QMUIButton
-
See moreQMUIToolbarButton
是用于底部工具栏的按钮Declaration
Objective-C
@interface QMUIToolbarButton : UIButton
Swift
class QMUIToolbarButton : UIButton
-
QMUINavigationButton 有两部分组成: 一部分是 UIBarButtonItem (QMUINavigationButton),提供比系统更便捷的类方法来快速初始化一个 UIBarButtonItem,推荐首选这种方式(原则是能用系统的尽量用系统的,不满足才用自定义的)。 另一部分就是 QMUINavigationButton,会提供一个按钮,作为 customView 给 UIBarButtonItem 使用,这种常用于自定义的返回按钮。 对于第二种按钮,会尽量保证样式、布局看起来都和系统的 UIBarButtonItem 一致,所以内部做了许多 iOS 版本兼容的微调。
See moreDeclaration
Objective-C
@interface QMUINavigationButton : UIButton
Swift
class QMUINavigationButton : UIButton
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIConsoleToolbar : UIView @property(nonatomic, strong, readonly) QMUIButton *levelButton; @property(nonatomic, strong, readonly) QMUIButton *nameButton; @property(nonatomic, strong, readonly) QMUIButton *clearButton; @property(nonatomic, strong, readonly) QMUITextField *searchTextField; @property(nonatomic, strong, readonly) UILabel *searchResultCountLabel; @property(nonatomic, strong, readonly) QMUIButton *searchResultPreviousButton; @property(nonatomic, strong, readonly) QMUIButton *searchResultNextButton; - (void)setNeedsLayoutSearchResultViews; @end
Swift
class QMUIConsoleToolbar : UIView
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIConsoleViewController : QMUICommonViewController @property(nonatomic, strong, readonly) QMUIButton *popoverButton; @property(nonatomic, strong, readonly) QMUITextView *textView; @property(nonatomic, strong, readonly) QMUIConsoleToolbar *toolbar; @property(nonatomic, strong, readonly) NSDateFormatter *dateFormatter; @property(nonatomic, strong) UIColor *backgroundColor; - (void)logWithLevel:(nullable NSString *)level name:(nullable NSString *)name logString:(id)logString; - (void)log:(id)logString; - (void)clear; @end
Swift
class QMUIConsoleViewController
-
可作为navgationItem.titleView 的标题控件。
支持主副标题,且可控制主副标题的布局方式(水平或垂直);支持在左边显示loading,在右边显示accessoryView(如箭头)。
默认情况下 titleView 是不支持点击的,需要支持点击的情况下,请把
userInteractionEnabled
设为YES
。若要监听 titleView 的点击事件,有两种方法:
- 使用 UIControl 默认的 addTarget:action:forControlEvents: 方式。这种适用于单纯的点击,不需要涉及到状态切换等。
- 使用 QMUINavigationTitleViewDelegate 提供的接口。这种一般配合 titleView.accessoryType 来使用,这样就不用自己去做 accessoryView 的旋转、active 状态的维护等。
Declaration
Objective-C
@interface QMUINavigationTitleView : UIControl
Swift
class QMUINavigationTitleView : UIControl
-
Undocumented
Declaration
Objective-C
@interface QMUISearchBar : UISearchBar @end
Swift
class QMUISearchBar : UISearchBar
-
配合 QMUIImagePickerViewController 使用的工具类
See moreDeclaration
Objective-C
@interface QMUIImagePickerHelper : NSObject
Swift
class QMUIImagePickerHelper : NSObject
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIAlbumTableViewCell : QMUITableViewCell @property(nonatomic, assign) CGFloat albumImageSize UI_APPEARANCE_SELECTOR; // 相册缩略图的大小 @property(nonatomic, assign) CGFloat albumImageMarginLeft UI_APPEARANCE_SELECTOR; // 相册缩略图的 left,-1 表示自动保持与上下 margin 相等 @property(nonatomic, assign) UIEdgeInsets albumNameInsets UI_APPEARANCE_SELECTOR; // 相册名称的上下左右间距 @property(nullable, nonatomic, strong) UIFont *albumNameFont UI_APPEARANCE_SELECTOR; // 相册名的字体 @property(nullable, nonatomic, strong) UIColor *albumNameColor UI_APPEARANCE_SELECTOR; // 相册名的颜色 @property(nullable, nonatomic, strong) UIFont *albumAssetsNumberFont UI_APPEARANCE_SELECTOR; // 相册资源数量的字体 @property(nullable, nonatomic, strong) UIColor *albumAssetsNumberColor UI_APPEARANCE_SELECTOR; // 相册资源数量的颜色 @end
Swift
class QMUIAlbumTableViewCell : QMUITableViewCell
-
当前设备照片里的相簿列表,使用方式:
- 使用 init 初始化。
- 指定一个 albumViewControllerDelegate,并实现 @required 方法。
Warning
注意,iOS 访问相册需要得到授权,建议先询问用户授权,通过了再进行 QMUIAlbumViewController 的初始化工作。关于授权的代码,可参考 QMUI Demo 项目里的 [QDImagePickerExampleViewController authorizationPresentAlbumViewControllerWithTitle] 方法。See
[QMUIAssetsManager requestAuthorization:]Declaration
Objective-C
@interface QMUIAlbumViewController
Swift
class QMUIAlbumViewController
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUITableViewCell : UITableViewCell @property(nonatomic, assign, readonly) UITableViewCellStyle style; /** * 调整 imageView 的位置偏移,常用于调整 imageView 和 textLabel 之间的间距,默认为 UIEdgeInsetsZero。 * @warning 目前只对 UITableViewCellStyleDefault 和 UITableViewCellStyleSubtitle 类型的 cell 开放 */ @property(nonatomic, assign) UIEdgeInsets imageEdgeInsets; /** * 调整 textLabel 的位置偏移,默认为 UIEdgeInsetsZero。 * @warning 目前只对 UITableViewCellStyleDefault 和 UITableViewCellStyleSubtitle 类型的 cell 开放 */ @property(nonatomic, assign) UIEdgeInsets textLabelEdgeInsets; /// 调整 detailTextLabel 的位置偏移,默认为 UIEdgeInsetsZero。 @property(nonatomic, assign) UIEdgeInsets detailTextLabelEdgeInsets; /** 调整右边 accessoryView 的布局偏移,默认为 UIEdgeInsetsZero。 @warning 对系统原生的 view 不生效(例如向右箭头、“i”详情按钮等),如果通过配置表设置了 TableViewCellDisclosureIndicatorImage,由于该配置本质上是使用了自定义的 accessoryView 来实现,所以这个属性对其生效。 */ @property(nonatomic, assign) UIEdgeInsets accessoryEdgeInsets; /** 调整右边 accessoryView 的点击响应区域,可用负值扩大点击范围,默认为(-12, -12, -12, -12)。 @warning 对系统原生的 view 不生效(例如向右箭头、“i”详情按钮等),如果通过配置表设置了 TableViewCellDetailButtonImage,由于该配置本质上是使用了自定义的 accessoryView 来实现,所以这个属性对其生效。 */ @property(nonatomic, assign) UIEdgeInsets accessoryHitTestEdgeInsets; /// 设置当前 cell 是否可用,setter 方法里面会修改当前的 subviews 样式,以展示出禁用的样式,具体样式请查看源码。 @property(nonatomic, assign, getter = isEnabled) BOOL enabled; /// 保存对 tableView 的弱引用,在布局时可能会使用到 tableView 的一些属性例如 separatorColor 等 @property(nonatomic, weak, nullable) UITableView *parentTableView; /** * cell 处于 section 中的位置,要求: * 1. cell 使用 initForTableViewXxx 方法初始化,或者初始化完后为 parentTableView 属性赋值。 * 2. 在 cellForRow 里调用 [cell updateCellAppearanceWithIndexPath:] 方法。 * 3. 之后即可通过 cellPosition 获取到正确的位置。 */ @property(nonatomic, assign, readonly) QMUITableViewCellPosition cellPosition; /** * 首选初始化方法 * * @param tableView cell所在的tableView * @param style tableView的style * @param reuseIdentifier tableView的reuseIdentifier * * @return 一个QMUITableViewCell实例 */ - (nullable instancetype)initForTableView:(nullable UITableView *)tableView withStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier; /// 同上 - (nullable instancetype)initForTableView:(nullable UITableView *)tableView withReuseIdentifier:(NSString *)reuseIdentifier; @end
Swift
class QMUITableViewCell : UITableViewCell
-
图片选择空间里的九宫格 cell,支持显示 checkbox、饼状进度条及重试按钮(iCloud 图片需要)
See moreDeclaration
Objective-C
@interface QMUIImagePickerCollectionViewCell : UICollectionViewCell
Swift
class QMUIImagePickerCollectionViewCell : UICollectionViewCell
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIImagePickerPreviewViewController : QMUIImagePreviewViewController <QMUIImagePreviewViewDelegate> @property(nullable, nonatomic, weak) id<QMUIImagePickerPreviewViewControllerDelegate> delegate; @property(nullable, nonatomic, strong) UIColor *toolBarBackgroundColor UI_APPEARANCE_SELECTOR; @property(nullable, nonatomic, strong) UIColor *toolBarTintColor UI_APPEARANCE_SELECTOR; @property(nullable, nonatomic, strong, readonly) UIView *topToolBarView; @property(nullable, nonatomic, strong, readonly) QMUINavigationButton *backButton; @property(nullable, nonatomic, strong, readonly) QMUIButton *checkboxButton; /// 由于组件需要通过本地图片的 QMUIAsset 对象读取图片的详细信息,因此这里的需要传入的是包含一个或多个 QMUIAsset 对象的数组 @property(nullable, nonatomic, strong) NSMutableArray<QMUIAsset *> *imagesAssetArray; @property(nullable, nonatomic, strong) NSMutableArray<QMUIAsset *> *selectedImageAssetArray; @property(nonatomic, assign) QMUIAssetDownloadStatus downloadStatus; /// 最多可以选择的图片数,默认为无穷大 @property(nonatomic, assign) NSUInteger maximumSelectImageCount; /// 最少需要选择的图片数,默认为 0 @property(nonatomic, assign) NSUInteger minimumSelectImageCount; /// 选择图片超出最大图片限制时 alertView 的标题 @property(nullable, nonatomic, copy) NSString *alertTitleWhenExceedMaxSelectImageCount; /// 选择图片超出最大图片限制时 alertView 的标题 @property(nullable, nonatomic, copy) NSString *alertButtonTitleWhenExceedMaxSelectImageCount; /** * 更新数据并刷新 UI,手工调用 * * @param imageAssetArray 包含所有需要展示的图片的数组 * @param selectedImageAssetArray 包含所有需要展示的图片中已经被选中的图片的数组 * @param currentImageIndex 当前展示的图片在 imageAssetArray 的索引 * @param singleCheckMode 是否为单选模式,如果是单选模式,则不显示 checkbox */ - (void)updateImagePickerPreviewViewWithImagesAssetArray:(NSMutableArray<QMUIAsset *> * _Nullable)imageAssetArray selectedImageAssetArray:(NSMutableArray<QMUIAsset *> * _Nullable)selectedImageAssetArray currentImageIndex:(NSInteger)currentImageIndex singleCheckMode:(BOOL)singleCheckMode; @end
Swift
class QMUIImagePickerPreviewViewController
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIImagePickerViewController : QMUICommonViewController <UICollectionViewDataSource, UICollectionViewDelegate, QMUIImagePickerPreviewViewControllerDelegate> @property(nullable, nonatomic, weak) id<QMUIImagePickerViewControllerDelegate> imagePickerViewControllerDelegate; /* * 图片的最小尺寸,布局时如果有剩余空间,会将空间分配给图片大小,所以最终显示出来的大小不一定等于minimumImageWidth。默认是75。 * @warning collectionViewLayout 和 collectionView 可能有设置 sectionInsets 和 contentInsets,所以设置几行不可以简单的通过 screenWdith / columnCount 来获得 */ @property(nonatomic, assign) CGFloat minimumImageWidth UI_APPEARANCE_SELECTOR; @property(nullable, nonatomic, strong, readonly) UICollectionViewFlowLayout *collectionViewLayout; @property(nullable, nonatomic, strong, readonly) UICollectionView *collectionView; @property(nullable, nonatomic, strong, readonly) UIView *operationToolBarView; @property(nullable, nonatomic, strong, readonly) QMUIButton *previewButton; @property(nullable, nonatomic, strong, readonly) QMUIButton *sendButton; @property(nullable, nonatomic, strong, readonly) UILabel *imageCountLabel; /// 也可以直接传入 QMUIAssetsGroup,然后读取其中的 QMUIAsset 并储存到 imagesAssetArray 中,传入后会赋值到 QMUIAssetsGroup,并自动刷新 UI 展示 - (void)refreshWithAssetsGroup:(QMUIAssetsGroup * _Nullable)assetsGroup; @property(nullable, nonatomic, strong, readonly) NSMutableArray<QMUIAsset *> *imagesAssetArray; @property(nullable, nonatomic, strong, readonly) QMUIAssetsGroup *assetsGroup; /// 当前被选择的图片对应的 QMUIAsset 对象数组 @property(nullable, nonatomic, strong, readonly) NSMutableArray<QMUIAsset *> *selectedImageAssetArray; /// 是否允许图片多选,默认为 YES。如果为 NO,则不显示 checkbox 和底部工具栏。 @property(nonatomic, assign) BOOL allowsMultipleSelection; /// 最多可以选择的图片数,默认为无符号整形数的最大值,相当于没有限制 @property(nonatomic, assign) NSUInteger maximumSelectImageCount; /// 最少需要选择的图片数,默认为 0 @property(nonatomic, assign) NSUInteger minimumSelectImageCount; /// 选择图片超出最大图片限制时 alertView 的标题 @property(nullable, nonatomic, copy) NSString *alertTitleWhenExceedMaxSelectImageCount; /// 选择图片超出最大图片限制时 alertView 底部按钮的标题 @property(nullable, nonatomic, copy) NSString *alertButtonTitleWhenExceedMaxSelectImageCount; /** * 加载相册列表时会出现 loading,若需要自定义 loading 的形式,可将该属性置为 NO,默认为 YES。 * @see imagePickerViewControllerWillStartLoading: & imagePickerViewControllerDidFinishLoading: */ @property(nonatomic, assign) BOOL shouldShowDefaultLoadingView; @end
Swift
class QMUIImagePickerViewController : UICollectionViewDataSource, UICollectionViewDelegate, QMUIImagePickerPreviewViewControllerDelegate
-
QMUILabel
支持通过contentEdgeInsets
属性来实现类似padding的效果。同时通过将
See morecanPerformCopyAction
置为YES
来开启长按复制文本的功能,复制 item 的文案可通过 menuItemTitleForCopyAction 修改,长按时label的背景色默认为highlightedBackgroundColor
Declaration
Objective-C
@interface QMUILabel : UILabel
Swift
class QMUILabel : UILabel
-
用于管理 QMUILog name 的调试界面,可直接 init 使用
See moreDeclaration
Objective-C
@interface QMUILogManagerViewController
Swift
class QMUILogManagerViewController
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUITableView : UITableView @property(nonatomic, weak) id<QMUITableViewDelegate> delegate; @property(nonatomic, weak) id<QMUITableViewDataSource> dataSource; @end
Swift
class QMUITableView : UITableView
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIVisualEffectView : UIVisualEffectView @property(nonatomic, strong) UIColor *foregroundColor UI_APPEARANCE_SELECTOR; @end
Swift
class QMUIVisualEffectView : UIVisualEffectView
-
一个方便地监控 UIScrollView 滚动的类,可在 didScrollBlock 里做一些与滚动位置相关的事情。
使用方式:
- 用 init 初始化。
- 通过 scrollView 绑定一个 UIScrollView。
- 在 didScrollBlock 里做一些与滚动位置相关的事情。
Declaration
Objective-C
@interface QMUIScrollAnimator : NSObject <UIScrollViewDelegate>
Swift
class QMUIScrollAnimator : NSObject, UIScrollViewDelegate
-
实现通过界面上的 UIScrollView 滚动来控制顶部导航栏外观的类,导航栏外观会跟随滚动距离的变化而变化。
使用方式:
- 用 init 方法初始化。
- 通过 scrollView 属性关联一个 UIScrollView。
- 修改 offsetYToStartAnimation 调整动画触发的滚动位置。
- 修改 distanceToStopAnimation 调整动画触发后滚动多久到达终点。
Note
注意,由于在同个 UINavigationController 里的所有 viewController 的 navigationBar 都是共享的,所以如果修改了 navigationBar 的样式,需要自行处理界面切换时 navigationBar 的样式恢复。Note
注意,为了性能考虑,在 progress 达到 0 后再往上滚,或者 progress 达到 1 后再往下滚,都不会再触发那一系列 animationBlock。Declaration
Objective-C
@interface QMUINavigationBarScrollingAnimator : QMUIScrollAnimator
Swift
class QMUINavigationBarScrollingAnimator : QMUIScrollAnimator
-
实现通过界面上的 UIScrollView 滚动来控制顶部导航栏外观的类,当滚动到某个位置时,即触发导航栏外观的变化。
使用方式:
- 用 init 方法初始化。
- 通过 scrollView 属性关联一个 UIScrollView。
- 修改 offsetYToStartAnimation 调整动画触发的滚动位置。
Note
注意,由于在同个 UINavigationController 里的所有 viewController 的 navigationBar 都是共享的,所以如果修改了 navigationBar 的样式,需要自行处理界面切换时 navigationBar 的样式恢复。Declaration
Objective-C
@interface QMUINavigationBarScrollingSnapAnimator : QMUIScrollAnimator
Swift
class QMUINavigationBarScrollingSnapAnimator : QMUIScrollAnimator
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUICellHeightCache : NSObject - (BOOL)existsHeightForKey:(id<NSCopying>)key; - (void)cacheHeight:(CGFloat)height byKey:(id<NSCopying>)key; - (CGFloat)heightForKey:(id<NSCopying>)key; - (void)invalidateHeightForKey:(id<NSCopying>)key; - (void)invalidateAllHeightCache; @end
Swift
class QMUICellHeightCache : NSObject
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUICellHeightIndexPathCache : NSObject @property(nonatomic, assign) BOOL automaticallyInvalidateEnabled;// TODO: 这个要放在 tableView 那边 - (BOOL)existsHeightAtIndexPath:(NSIndexPath *)indexPath; - (void)cacheHeight:(CGFloat)height byIndexPath:(NSIndexPath *)indexPath; - (CGFloat)heightForIndexPath:(NSIndexPath *)indexPath; - (void)invalidateHeightAtIndexPath:(NSIndexPath *)indexPath; - (void)invalidateAllHeightCache; @end
Swift
class QMUICellHeightIndexPathCache : NSObject
-
弹窗组件基类,自带
headerView
、contentView
、footerView
,并通过addCancelButtonWithText:block:
、addSubmitButtonWithText:block:
方法来添加取消、确定按钮。 建议将一个自定义的UIView设置给contentView
属性,此时弹窗将会自动帮你计算大小并布局。大小取决于你的contentView的sizeThatFits:返回值。 弹窗继承自QMUICommonViewController
,因此可直接使用self.titleView的功能来实现双行标题,具体请查看QMUINavigationTitleView
。QMUIDialogViewController
支持以类似UIAppearance
的方式来统一设置全局的dialog样式,例如[QMUIDialogViewController appearance].headerViewHeight = 48;
。See
QMUIDialogSelectionViewControllerSee
QMUIDialogTextFieldViewControllerDeclaration
Objective-C
@interface QMUIDialogViewController < QMUIModalPresentationContentViewControllerProtocol, QMUIModalPresentationComponentProtocol>
Swift
class QMUIDialogViewController : QMUIModalPresentationContentViewControllerProtocol, QMUIModalPresentationComponentProtocol
-
支持列表选择的弹窗,通过
See moreitems
指定要展示的所有选项(暂时只支持NSString
)。默认使用单选,可通过allowsMultipleSelection
支持多选。 单选模式下,通过selectedItemIndex
可获取当前被选中的选项,也可在初始化完dialog后设置这个属性来达到默认值的效果。 多选模式下,通过selectedItemIndexes
可获取当前被选中的多个选项,可也在初始化完dialog后设置这个属性来达到默认值的效果。Declaration
Objective-C
@interface QMUIDialogSelectionViewController : QMUIDialogViewController <QMUITableViewDelegate, QMUITableViewDataSource>
Swift
class QMUIDialogSelectionViewController : QMUIDialogViewController, QMUITableViewDelegate, QMUITableViewDataSource
-
支持单行文本输入的弹窗,可通过
See moretextField.maximumLength
来控制最长可输入的字符,超过则无法继续输入。 可通过enablesSubmitButtonAutomatically
来自动设置submitButton.enabled
的状态Declaration
Objective-C
@interface QMUIDialogTextFieldViewController : QMUIDialogViewController
Swift
class QMUIDialogTextFieldViewController : QMUIDialogViewController
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIPieProgressView : UIControl /** 进度动画的时长,默认为 0.5 */ @property(nonatomic, assign) IBInspectable CFTimeInterval progressAnimationDuration; /** 当前进度值,默认为 0.0。调用 `setProgress:` 相当于调用 `setProgress:animated:NO` */ @property(nonatomic, assign) IBInspectable float progress; /** 外边框的大小,默认为 1。 */ @property(nonatomic, assign) IBInspectable CGFloat borderWidth; /** 外边框与内部扇形之间的间隙,默认为 0。 */ @property(nonatomic, assign) IBInspectable CGFloat borderInset; /** 线宽,用于环形绘制,默认为 0。 */ @property(nonatomic, assign) IBInspectable CGFloat lineWidth; /** 绘制形状,默认是扇形。 */ @property(nonatomic, assign) IBInspectable QMUIPieProgressViewShape shape; /** 修改当前的进度,会触发 UIControlEventValueChanged 事件 @param progress 当前的进度,取值范围 [0.0-1.0] @param animated 是否以动画来表现 */ - (void)setProgress:(float)progress animated:(BOOL)animated; @end
Swift
class QMUIPieProgressView : UIControl
-
用于 QMUIPopupMenuView 的 item 基类,便于自定义各种类型的 item。若有 subview 请直接添加到 self 上,自身大小的计算请写到 sizeThatFits:,布局写到 layoutSubviews。
Declaration
Objective-C
@interface QMUIPopupMenuBaseItem : UIView <QMUIPopupMenuItemProtocol>
Swift
class QMUIPopupMenuBaseItem : UIView, QMUIPopupMenuItemProtocol
-
配合 QMUIPopupMenuView 使用,用于可点击的菜单项。 支持显示图片和标题,以及点击事件的回调。 可在 QMUIPopupMenuView 里统一修改菜单项的样式,如果某个菜单项需要特殊调整,可通过 QMUIPopupMenuButtonItem.button 拿到 view 并进行调整。
See moreDeclaration
Objective-C
@interface QMUIPopupMenuButtonItem : QMUIPopupMenuBaseItem
Swift
class QMUIPopupMenuButtonItem : QMUIPopupMenuBaseItem
-
用于弹出浮层里显示一行一行的菜单的控件。 使用方式:
- 调用 init 方法初始化。
- 按需设置分隔线、item 高度等样式。
- 设置完样式后再通过 items 或 itemSections 添加菜单项。
- 通过为 sourceBarItem/sourceView/sourceRect 三者中的一个赋值,来决定浮层布局的位置(参考父类)。
- 调用 showWithAnimated: 即可显示(参考父类)。
注意,QMUIPopupMenuView 的大小默认是按内容自适应的(item 的 sizeThatFits),但同时又受 maximumWidth/minimumWidth 的限制。
See moreDeclaration
Objective-C
@interface QMUIPopupMenuView : QMUIPopupContainerView
Swift
class QMUIPopupMenuView : QMUIPopupContainerView
-
更多操作面板控件,类似系统的相册分享面板,以及微信的 webview 分享面板。功能特性包括:
- 支持多行,每行支持多个 item,由二维数组 items 控制。
- 默认自带取消按钮,也可自行隐藏。
- 支持以 UIAppearance 的方式配置样式皮肤。
Declaration
Objective-C
@interface QMUIMoreOperationController : UIViewController <QMUIModalPresentationContentViewControllerProtocol, QMUIModalPresentationViewControllerDelegate, QMUIModalPresentationComponentProtocol>
Swift
class QMUIMoreOperationController : UIViewController, QMUIModalPresentationContentViewControllerProtocol, QMUIModalPresentationViewControllerDelegate, QMUIModalPresentationComponentProtocol
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIMoreOperationItemView : QMUIButton @property(nullable, nonatomic, strong, readonly) NSIndexPath *indexPath; @property(nonatomic, assign) NSInteger tag; + (instancetype)itemViewWithImage:(UIImage * _Nullable)image title:(NSString * _Nullable)title handler:(void (^ _Nullable)(QMUIMoreOperationController *moreOperationController, QMUIMoreOperationItemView *itemView))handler; + (instancetype)itemViewWithImage:(UIImage * _Nullable)image selectedImage:(UIImage * _Nullable)selectedImage title:(NSString * _Nullable)title selectedTitle:(NSString * _Nullable)selectedTitle handler:(void (^ _Nullable)(QMUIMoreOperationController *moreOperationController, QMUIMoreOperationItemView *itemView))handler; + (instancetype)itemViewWithImage:(UIImage * _Nullable)image title:(NSString * _Nullable)title tag:(NSInteger)tag handler:(void (^ _Nullable)(QMUIMoreOperationController *moreOperationController, QMUIMoreOperationItemView *itemView))handler; + (instancetype)itemViewWithImage:(UIImage * _Nullable)image selectedImage:(UIImage * _Nullable)selectedImage title:(NSString * _Nullable)title selectedTitle:(NSString * _Nullable)selectedTitle tag:(NSInteger)tag handler:(void (^ _Nullable)(QMUIMoreOperationController *moreOperationController, QMUIMoreOperationItemView *itemView))handler; @end
Swift
class QMUIMoreOperationItemView
-
通用的空界面控件,支持显示 loading、标题和副标题提示语、占位图片,QMUICommonViewController 内已集成一个 emptyView,无需额外添加。
See moreDeclaration
Objective-C
@interface QMUIEmptyView : UIView
Swift
class QMUIEmptyView : UIView
-
用于做九宫格布局,会将内部所有的 subview 根据指定的列数和行高,把每个 item(也即 subview) 拉伸到相同的大小。
支持在 item 和 item 之间显示分隔线,分隔线支持虚线。
Warning
注意分隔线是占位的,把 item 隔开,而不是盖在某个 item 上。Declaration
Objective-C
@interface QMUIGridView : UIView
Swift
class QMUIGridView : UIView
-
QMUIKeyboardManager
提供了方便管理键盘事件的方案,使用的场景是需要跟随键盘的显示或者隐藏来更改界面的 UI,例如输入框跟随在键盘的顶部。 由于键盘通知是整个 App 全局的,所以经常会遇到 A 的键盘监听回调里接收到 B 的键盘事件,这样的情况往往不是我们想要的,即使可以通过判断当前的 firstResponder 来区分,但还是不能完美的解决问题或者有时候解决起来非常麻烦。QMUIKeyboardManager
通过delegateEnabled
和targetResponder
等属性来方便地控制 firstResponder,从而可以实现某个键盘监听回调方法只响应某个 UIResponder 或者某几个 UIResponder 触发的键盘通知。 使用方式:- 使用 initWithDelegate: 方法初始化
- 通过 addTargetResponder: 的方式将要监听的输入框添加进来
- 在 delegate 方法里(一般用 keyboardWillChangeFrameWithUserInfo:)处理键盘位置变化时的布局
另外 QMUIKeyboardManager 同时集成在了 UITextField(QMUI) 和 UITextView(QMUI) 里,具体请查看对应文件。
See
UITextField(QMUI)See
UITextView(QMUI)Declaration
Objective-C
@interface QMUIKeyboardManager : NSObject
Swift
class QMUIKeyboardManager : NSObject
-
Undocumented
See moreDeclaration
Objective-C
@interface QMUIKeyboardUserInfo : NSObject /** * 所在的KeyboardManager */ @property(nonatomic, weak, readonly) QMUIKeyboardManager *keyboardManager; /** * 当前键盘的notification */ @property(nonatomic, strong, readonly) NSNotification *notification; /** * notification自带的userInfo */ @property(nonatomic, strong, readonly) NSDictionary *originUserInfo; /** * 触发键盘事件的UIResponder,注意这里的 `targetResponder` 不一定是通过 `addTargetResponder:` 添加的 UIResponder,而是当前触发键盘事件的 UIResponder。 */ @property(nonatomic, weak, readonly) UIResponder *targetResponder; /** * 获取键盘实际宽度 */ @property(nonatomic, assign, readonly) CGFloat width; /** * 获取键盘的实际高度 */ @property(nonatomic, assign, readonly) CGFloat height; /** * 获取当前键盘在view上的可见高度,也就是键盘和view重叠的高度。如果view=nil,则直接返回键盘的实际高度。 */ - (CGFloat)heightInView:(UIView *)view; /** * 获取键盘beginFrame */ @property(nonatomic, assign, readonly) CGRect beginFrame; /** * 获取键盘endFrame */ @property(nonatomic, assign, readonly) CGRect endFrame; /** * 获取键盘出现动画的duration,对于第三方键盘,这个值有可能为0 */ @property(nonatomic, assign, readonly) NSTimeInterval animationDuration; /** * 获取键盘动画的Curve参数 */ @property(nonatomic, assign, readonly) UIViewAnimationCurve animationCurve; /** * 获取键盘动画的Options参数 */ @property(nonatomic, assign, readonly) UIViewAnimationOptions animationOptions; @end
Swift
class QMUIKeyboardUserInfo : NSObject
-
适用于 UITableView 的 sectionHeaderFooterView,提供的特性包括:
- 支持单个 UILabel,该 label 支持多行文字。
- 支持右边添加一个 accessoryView(注意,设置 accessoryView 之前请先保证自身大小正确)。
- 支持调整 headerFooterView 的 padding。
- 支持应用配置表的样式。
使用方式: 基本与系统的 UITableViewHeaderFooterView 使用方式一致,额外需要做的事情有:
- 如果要支持高度自动根据内容变化,则需要重写 tableView:heightForHeaderInSection:、tableView:heightForFooterInSection:,在里面调用 headerFooterView 的 sizeThatFits:。
- 如果要应用配置表样式,则设置 parentTableView 和 type 这两个属性即可。
Declaration
Objective-C
@interface QMUITableViewHeaderFooterView : UITableViewHeaderFooterView
Swift
class QMUITableViewHeaderFooterView : UITableViewHeaderFooterView
-
提供一个常见的通用表情面板,能为绑定的
UITextField
或UITextView
提供表情的相关功能,包括点击表情输入对应的表情名字、点击删除按钮删除表情。 使用方式:- 使用 init 方法初始化。
- 通过
boundTextField
或boundTextView
关联一个输入框,建议这些输入框使用QMUITextField
或QMUITextView
,原因看下面的 warning。 - 将所有表情通过
self.emotionView.emotions
设置进去,注意这个数组里的所有QMUIEmotion
的displayName
都应该使用左右标识符包裹起来(例如中括号“[]”),并且所有表情的左右标识符都应该保持一致。 - 将
self.emotionView
add 到界面上即可。
Warning
一个QMUIEmotionInputManager
无法同时绑定boundTextField
和boundTextView
,在两者都绑定的情况下,优先使用boundTextField
。Warning
由于QMUIEmotionInputManager
里面多个地方会调用boundTextView.text
,而setText:
并不会触发UITextViewDelegate
的textViewDidChange:
或UITextViewTextDidChangeNotification
,以及UITextField
的UIControlEventEditingChanged
事件,从而在刷新表情面板里的发送按钮的enabled状态时可能不及时,所以推荐使用QMUITextView
代替UITextView
、用QMUITextField
代替UITextField
,并确保它们的shouldResponseToProgrammaticallyTextChanges
属性是YES
(默认即为YES
)。Warning
由于表情的插入、删除都会受当前输入框的光标所在位置的影响,所以请在适当的时机更新selectedRangeForBoundTextInput
的值,具体情况请查看该属性的注释。Declaration
Objective-C
@interface QMUIEmotionInputManager : NSObject
Swift
class QMUIEmotionInputManager : NSObject
-
一个简单实现的有序的 key-value 容器,通过 initWithKeysAndObjects: 初始化后,用下标访问即可,如 dict[0] 或 dict[key]
See moreDeclaration
Objective-C
@interface QMUIOrderedDictionary<__covariant KeyType, __covariant ObjectType> : NSObject
Swift
class QMUIOrderedDictionary<KeyType, ObjectType> : NSObject where KeyType : AnyObject, ObjectType : AnyObject
-
Declaration
Objective-C
@interface QMUISlider : UISlider
Swift
class QMUISlider : UISlider
-
简易的跑马灯 label 控件,在文字超过 label 可视区域时会自动开启跑马灯效果展示文字,文字滚动时是首尾连接的效果(参考播放音乐时系统锁屏界面顶部的音乐标题)。
Warning
lineBreakMode 默认为 NSLineBreakByClipping(UILabel 默认值为 NSLineBreakByTruncatingTail)。Warning
textAlignment 暂不支持 NSTextAlignmentJustified 和 NSTextAlignmentNatural。Warning
会忽略 numberOfLines 属性,强制以 1 来展示。Declaration
Objective-C
@interface QMUIMarqueeLabel : UILabel
Swift
class QMUIMarqueeLabel : UILabel
-
支持按页横向滚动的 UICollectionViewLayout,可切换不同类型的滚动动画。
Warning
item 的大小和布局仅支持通过 UICollectionViewFlowLayout 的 property 系列属性修改,也即每个 item 都应相等。对于通过 delegate 方式返回各不相同的 itemSize、sectionInset 的场景是不支持的。Declaration
Objective-C
@interface QMUICollectionViewPagingLayout : UICollectionViewFlowLayout
Swift
class QMUICollectionViewPagingLayout : UICollectionViewFlowLayout
-
简单封装了 QMUIToastView,支持弹出纯文本、loading、succeed、error、info 等五种 tips。如果这些接口还满足不了业务的需求,可以通过 QMUITips 的分类自行添加接口。 注意用类方法显示 tips 的话,会导致父类的 willShowBlock 无法正常工作,具体请查看 willShowBlock 的注释。
Warning
使用类方法,除了 showLoading 系列方法不会自动隐藏外,其他方法如果没有 delay 参数,则会自动隐藏See
[QMUIToastView willShowBlock]Declaration
Objective-C
@interface QMUITips
Swift
class QMUITips
-
自定义 UITextView,提供的特性如下:
- 支持 placeholder 并支持更改 placeholderColor;若使用了富文本文字,则 placeholder 的样式也会跟随文字的样式(除了 placeholder 颜色)
- 支持在文字发生变化时计算内容高度并通知 delegate。
- 支持限制输入框最大高度,一般配合第 2 点使用。
- 支持限制输入的文本的最大长度,默认不限制。
- 修正系统 UITextView 在输入时自然换行的时候,contentOffset 的滚动位置没有考虑 textContainerInset.bottom
Declaration
Objective-C
@interface QMUITextView : UITextView
Swift
class QMUITextView : UITextView
-
代表一个表情的数据对象
See moreDeclaration
Objective-C
@interface QMUIEmotion : NSObject
Swift
class QMUIEmotion : NSObject
-
表情控件,支持任意表情的展示,每个表情以相同的大小显示。
使用方式:
- 通过
initWithFrame:
初始化,如果面板高度不变,建议在init时就设置好,若最终布局以父类的layoutSubviews
为准,则也可通过init
方法初始化,再在layoutSubviews
里计算布局 - 通过调整
paddingInPage
、emotionSize
等变量来自定义UI - 通过
emotions
设置要展示的表情 - 通过
didSelectEmotionBlock
设置选中表情时的回调,通过didSelectDeleteButtonBlock
来响应面板内的删除按钮 - 为
sendButton
添加addTarget:action:forState:
事件,从而触发发送逻辑
本控件支持通过
See moreUIAppearance
设置全局的默认样式。若要修改控件内的UIPageControl
的样式,可通过[UIPageControl appearanceWhenContainedInInstancesOfClasses:@[[QMUIEmotionView class]]]
的方式来修改。Declaration
Objective-C
@interface QMUIEmotionView : UIView <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
Swift
class QMUIEmotionView : UIView, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
- 通过
-
UIKit 仅提供了对 UIView 默认的 UIAppearance 支持,如果你是一个继承自 NSObject 的对象,想要使用 UIAppearance 能力,按 UIKit 公开的 API 是无法实现的,而 QMUIAppearance 对这种场景提供了支持。
使用方法(可参考 QMUIAlertController):
为目标类增加方法 +(instancetype)appearance; 方法,返回值类型使用 instancetype 是为了保证 Xcode 能正确进行代码提示。
为目标类支持 appearance 的属性、方法添加 UI_APPEARANCE_SELECTOR 标记,注意对于方法只有符合特定命名格式才支持,具体请查看 UIAppearance.h 顶部对宏 UI_APPEARANCE_SELECTOR 的注释。
在 +appearance 方法里通过 +[QMUIAppearance appearanceForClass:self] 得到 appearance 对象并返回。
在恰当的时机为目标类的 appearance 赋初始值,QMUI 通常在类的 +initialize 方法里赋值。
在类初始化实例的时候(例如 init 方法里)调用 -qmui_applyQMUIAppearance 为实例赋初始值,注意如果你的父类已经调用过的话,子类不需要再重复调用。
Note
特别的,如果你正在为一个 UIView 子类支持 UIAppearance,不需要用到 QMUIAppearance,直接将属性、方法加上 UI_APPEARANCE_SELECTOR 标记即可,也不需要通过 -qmui_applyAppearance 的方式赋初始值(除非你希望这个赋值时机提前,系统默认时机是在 didMoveToWindow 时),系统都已经帮你处理好了,具体可查看 UIKit Documentation。Declaration
Objective-C
@interface QMUIAppearance : NSObject
Swift
class QMUIAppearance : NSObject