Categories

The following categories are available globally.

  • UIView自动布局分类,兼容UIView和UILayoutGuide(iOS9)

    Note

    如果约束条件完全相同,会自动更新约束而不是重新添加。 另外,默认布局方式使用LTR,如果需要RTL布局,可通过fwAutoLayoutRTL统一启用
    See more

    Declaration

    Objective-C

    @interface UIView (FWAutoLayout)

UIViewController+FWAdaptive

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIViewController (FWAdaptive)
    
    /// 当前状态栏布局高度,导航栏隐藏时为0,推荐使用
    @property (nonatomic, assign, readonly) CGFloat fw_statusBarHeight NS_REFINED_FOR_SWIFT;
    
    /// 当前导航栏布局高度,隐藏时为0,推荐使用
    @property (nonatomic, assign, readonly) CGFloat fw_navigationBarHeight NS_REFINED_FOR_SWIFT;
    
    /// 当前顶部栏布局高度,导航栏隐藏时为0,推荐使用
    @property (nonatomic, assign, readonly) CGFloat fw_topBarHeight NS_REFINED_FOR_SWIFT;
    
    /// 当前标签栏布局高度,隐藏时为0,推荐使用
    @property (nonatomic, assign, readonly) CGFloat fw_tabBarHeight NS_REFINED_FOR_SWIFT;
    
    /// 当前工具栏布局高度,隐藏时为0,推荐使用
    @property (nonatomic, assign, readonly) CGFloat fw_toolBarHeight NS_REFINED_FOR_SWIFT;
    
    /// 当前底部栏布局高度,包含标签栏和工具栏,隐藏时为0,推荐使用
    @property (nonatomic, assign, readonly) CGFloat fw_bottomBarHeight NS_REFINED_FOR_SWIFT;
    
    @end

UILabel+FWUIKit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UILabel (FWUIKit)
    
    /// 快速设置attributedText样式,设置后调用setText:会自动转发到setAttributedText:方法
    @property (nonatomic, copy, nullable) NSDictionary<NSAttributedStringKey, id> *fw_textAttributes NS_REFINED_FOR_SWIFT;
    
    /// 快速设置文字的行高,优先级低于fwTextAttributes,设置后调用setText:会自动转发到setAttributedText:方法。小于0时恢复默认行高
    @property (nonatomic, assign) CGFloat fw_lineHeight NS_REFINED_FOR_SWIFT;
    
    /// 自定义内容边距,未设置时为系统默认。当内容为空时不参与intrinsicContentSize和sizeThatFits:计算,方便自动布局
    @property (nonatomic, assign) UIEdgeInsets fw_contentInset NS_REFINED_FOR_SWIFT;
    
    /// 纵向分布方式,默认居中
    @property (nonatomic, assign) UIControlContentVerticalAlignment fw_verticalAlignment NS_REFINED_FOR_SWIFT;
    
    /// 添加点击手势并自动识别NSLinkAttributeName|URL属性,点击高亮时回调链接,点击其它区域回调nil
    - (void)fw_addLinkGestureWithBlock:(void (^)(id _Nullable link))block NS_REFINED_FOR_SWIFT;
    
    /// 获取手势触发位置的文本属性,可实现行内点击效果等,allowsSpacing默认为NO空白处不可点击。为了识别更准确,attributedText需指定font
    - (NSDictionary<NSAttributedStringKey, id> *)fw_attributesWithGesture:(UIGestureRecognizer *)gesture allowsSpacing:(BOOL)allowsSpacing NS_REFINED_FOR_SWIFT;
    
    /// 快速设置标签
    - (void)fw_setFont:(nullable UIFont *)font textColor:(nullable UIColor *)textColor NS_REFINED_FOR_SWIFT;
    
    /// 快速设置标签并指定文本
    - (void)fw_setFont:(nullable UIFont *)font textColor:(nullable UIColor *)textColor text:(nullable NSString *)text NS_REFINED_FOR_SWIFT;
    
    /// 快速创建标签
    + (instancetype)fw_labelWithFont:(nullable UIFont *)font textColor:(nullable UIColor *)textColor NS_REFINED_FOR_SWIFT;
    
    /// 快速创建标签并指定文本
    + (instancetype)fw_labelWithFont:(nullable UIFont *)font textColor:(nullable UIColor *)textColor text:(nullable NSString *)text NS_REFINED_FOR_SWIFT;
    
    @end
    extension UILabel: SkeletonViewDataSource

UITextView+FWKeyboard

UITableView+FWDynamicLayout

UICollectionView+FWDynamicLayout

  • 集合自动计算并缓存cell高度分类,最底部view的MaxY即为cell高度,自定义方案实现

    如果使用系统自动尺寸,建议设置estimatedItemSize提高性能

    See more

    Declaration

    Objective-C

    @interface UICollectionView (FWDynamicLayout)
    extension UICollectionView: SkeletonViewDataSource

UITableViewCell+FWDynamicLayout

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UITableViewCell (FWDynamicLayout)
    
    /// 如果用来确定Cell所需高度的View是唯一的,请把此值设置为YES,可提升一定的性能
    @property (nonatomic, assign) BOOL fw_maxYViewFixed NS_REFINED_FOR_SWIFT;
    
    /// 最大Y视图的底部内边距,可避免新创建View来撑开Cell,默认0
    @property (nonatomic, assign) CGFloat fw_maxYViewPadding NS_REFINED_FOR_SWIFT;
    
    /// 最大Y视图是否撑开布局,需布局约束完整。默认NO,无需撑开布局;YES时padding不起作用
    @property (nonatomic, assign) BOOL fw_maxYViewExpanded NS_REFINED_FOR_SWIFT;
    
    /// 免注册创建UITableViewCell,内部自动处理缓冲池,默认Default类型
    + (instancetype)fw_cellWithTableView:(UITableView *)tableView NS_REFINED_FOR_SWIFT;
    
    /// 免注册alloc创建UITableViewCell,内部自动处理缓冲池,指定style类型
    + (instancetype)fw_cellWithTableView:(UITableView *)tableView
                                              style:(UITableViewCellStyle)style NS_REFINED_FOR_SWIFT;
    
    /// 免注册alloc创建UITableViewCell,内部自动处理缓冲池,指定style类型,指定reuseIdentifier
    + (instancetype)fw_cellWithTableView:(UITableView *)tableView
                                              style:(UITableViewCellStyle)style
                                    reuseIdentifier:(nullable NSString *)reuseIdentifier NS_REFINED_FOR_SWIFT;
    
    /// 根据配置自动计算cell高度,不使用缓存,子类可重写
    + (CGFloat)fw_heightWithTableView:(UITableView *)tableView
                     configuration:(FWCellConfigurationBlock)configuration NS_REFINED_FOR_SWIFT;
    
    @end
    extension UITableViewCell: SkeletonViewDelegate

UITableViewHeaderFooterView+FWDynamicLayout

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UITableViewHeaderFooterView (FWDynamicLayout)
    
    /// 如果用来确定HeaderFooterView所需高度的View是唯一的,请把此值设置为YES,可提升一定的性能
    @property (nonatomic, assign) BOOL fw_maxYViewFixed NS_REFINED_FOR_SWIFT;
    
    /// 最大Y视图的底部内边距,可避免新创建View来撑开HeaderFooterView,默认0
    @property (nonatomic, assign) CGFloat fw_maxYViewPadding NS_REFINED_FOR_SWIFT;
    
    /// 最大Y视图是否撑开布局,需布局约束完整。默认NO,无需撑开布局;YES时padding不起作用
    @property (nonatomic, assign) BOOL fw_maxYViewExpanded NS_REFINED_FOR_SWIFT;
    
    /// 免注册alloc创建UITableViewHeaderFooterView,内部自动处理缓冲池
    + (instancetype)fw_headerFooterViewWithTableView:(UITableView *)tableView NS_REFINED_FOR_SWIFT;
    
    /// 免注册alloc创建UITableViewHeaderFooterView,内部自动处理缓冲池,指定reuseIdentifier
    + (instancetype)fw_headerFooterViewWithTableView:(UITableView *)tableView reuseIdentifier:(nullable NSString *)reuseIdentifier NS_REFINED_FOR_SWIFT;
    
    /// 根据配置自动计算cell高度,不使用缓存,子类可重写
    + (CGFloat)fw_heightWithTableView:(UITableView *)tableView
                              type:(FWHeaderFooterViewType)type
                     configuration:(FWHeaderFooterViewConfigurationBlock)configuration NS_REFINED_FOR_SWIFT;
    
    @end
    extension UITableViewHeaderFooterView: SkeletonViewDelegate

UICollectionReusableView+FWDynamicLayout

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UICollectionReusableView (FWDynamicLayout)
    
    /// 如果用来确定ReusableView所需尺寸的View是唯一的,请把此值设置为YES,可提升一定的性能
    @property (nonatomic, assign) BOOL fw_maxYViewFixed NS_REFINED_FOR_SWIFT;
    
    /// 最大Y尺寸视图的底部内边距(横向滚动时为X),可避免新创建View来撑开ReusableView,默认0
    @property (nonatomic, assign) CGFloat fw_maxYViewPadding NS_REFINED_FOR_SWIFT;
    
    /// 最大Y视图是否撑开布局(横向滚动时为X),需布局约束完整。默认NO,无需撑开布局;YES时padding不起作用
    @property (nonatomic, assign) BOOL fw_maxYViewExpanded NS_REFINED_FOR_SWIFT;
    
    /// 免注册alloc创建UICollectionReusableView,内部自动处理缓冲池
    + (instancetype)fw_reusableViewWithCollectionView:(UICollectionView *)collectionView
                                                kind:(NSString *)kind
                                           indexPath:(NSIndexPath *)indexPath NS_REFINED_FOR_SWIFT;
    
    /// 免注册alloc创建UICollectionReusableView,内部自动处理缓冲池,指定reuseIdentifier
    + (instancetype)fw_reusableViewWithCollectionView:(UICollectionView *)collectionView
                                                kind:(NSString *)kind
                                           indexPath:(NSIndexPath *)indexPath
                                     reuseIdentifier:(nullable NSString *)reuseIdentifier NS_REFINED_FOR_SWIFT;
    
    /// 根据配置自动计算view大小,子类可重写
    + (CGSize)fw_sizeWithCollectionView:(UICollectionView *)collectionView
                                kind:(NSString *)kind
                       configuration:(FWReusableViewConfigurationBlock)configuration NS_REFINED_FOR_SWIFT;
    
    /// 根据配置自动计算view大小,固定宽度,子类可重写
    + (CGSize)fw_sizeWithCollectionView:(UICollectionView *)collectionView
                               width:(CGFloat)width
                                kind:(NSString *)kind
                       configuration:(FWReusableViewConfigurationBlock)configuration NS_REFINED_FOR_SWIFT;
    
    /// 根据配置自动计算view大小,固定高度,子类可重写
    + (CGSize)fw_sizeWithCollectionView:(UICollectionView *)collectionView
                              height:(CGFloat)height
                                kind:(NSString *)kind
                       configuration:(FWReusableViewConfigurationBlock)configuration NS_REFINED_FOR_SWIFT;
    
    @end
    extension UICollectionReusableView: SkeletonViewDelegate

UICollectionViewCell+FWDynamicLayout

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UICollectionViewCell (FWDynamicLayout)
    
    /// 如果用来确定Cell所需尺寸的View是唯一的,请把此值设置为YES,可提升一定的性能
    @property (nonatomic, assign) BOOL fw_maxYViewFixed NS_REFINED_FOR_SWIFT;
    
    /// 最大Y视图的底部内边距(横向滚动时为X),可避免新创建View来撑开Cell,默认0
    @property (nonatomic, assign) CGFloat fw_maxYViewPadding NS_REFINED_FOR_SWIFT;
    
    /// 最大Y视图是否撑开布局(横向滚动时为X),需布局约束完整。默认NO,无需撑开布局;YES时padding不起作用
    @property (nonatomic, assign) BOOL fw_maxYViewExpanded NS_REFINED_FOR_SWIFT;
    
    /// 免注册创建UICollectionViewCell,内部自动处理缓冲池
    + (instancetype)fw_cellWithCollectionView:(UICollectionView *)collectionView
                                   indexPath:(NSIndexPath *)indexPath NS_REFINED_FOR_SWIFT;
    
    /// 免注册创建UICollectionViewCell,内部自动处理缓冲池,指定reuseIdentifier
    + (instancetype)fw_cellWithCollectionView:(UICollectionView *)collectionView
                                   indexPath:(NSIndexPath *)indexPath
                             reuseIdentifier:(nullable NSString *)reuseIdentifier NS_REFINED_FOR_SWIFT;
    
    /// 根据配置自动计算view大小,子类可重写
    + (CGSize)fw_sizeWithCollectionView:(UICollectionView *)collectionView
                       configuration:(FWCollectionCellConfigurationBlock)configuration NS_REFINED_FOR_SWIFT;
    
    /// 根据配置自动计算view大小,固定宽度,子类可重写
    + (CGSize)fw_sizeWithCollectionView:(UICollectionView *)collectionView
                               width:(CGFloat)width
                       configuration:(FWCollectionCellConfigurationBlock)configuration NS_REFINED_FOR_SWIFT;
    
    /// 根据配置自动计算view大小,固定高度,子类可重写
    + (CGSize)fw_sizeWithCollectionView:(UICollectionView *)collectionView
                              height:(CGFloat)height
                       configuration:(FWCollectionCellConfigurationBlock)configuration NS_REFINED_FOR_SWIFT;
    
    @end

UIApplication+FWAdaptive

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIApplication (FWAdaptive)
    
    /// 是否是调试模式
    @property (class, nonatomic, assign, readonly) BOOL fw_isDebug NS_REFINED_FOR_SWIFT;
    
    @end

UIDevice+FWAdaptive

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIDevice (FWAdaptive)
    
    /// 是否是模拟器
    @property (class, nonatomic, assign, readonly) BOOL fw_isSimulator NS_REFINED_FOR_SWIFT;
    
    /// 是否是iPhone
    @property (class, nonatomic, assign, readonly) BOOL fw_isIphone NS_REFINED_FOR_SWIFT;
    /// 是否是iPad
    @property (class, nonatomic, assign, readonly) BOOL fw_isIpad NS_REFINED_FOR_SWIFT;
    /// 是否是Mac
    @property (class, nonatomic, assign, readonly) BOOL fw_isMac NS_REFINED_FOR_SWIFT;
    
    /// 界面是否横屏
    @property (class, nonatomic, assign, readonly) BOOL fw_isLandscape NS_REFINED_FOR_SWIFT;
    /// 设备是否横屏,无论支不支持横屏
    @property (class, nonatomic, assign, readonly) BOOL fw_isDeviceLandscape NS_REFINED_FOR_SWIFT;
    /// 设置界面方向,支持旋转方向时生效
    + (BOOL)fw_setDeviceOrientation:(UIDeviceOrientation)orientation NS_REFINED_FOR_SWIFT;
    
    /// iOS系统版本
    @property (class, nonatomic, assign, readonly) double fw_iosVersion NS_REFINED_FOR_SWIFT;
    /// 是否是指定iOS主版本
    + (BOOL)fw_isIos:(NSInteger)version NS_REFINED_FOR_SWIFT;
    /// 是否是大于等于指定iOS主版本
    + (BOOL)fw_isIosLater:(NSInteger)version NS_REFINED_FOR_SWIFT;
    
    /// 设备尺寸,跟横竖屏无关
    @property (class, nonatomic, assign, readonly) CGSize fw_deviceSize NS_REFINED_FOR_SWIFT;
    /// 设备宽度,跟横竖屏无关
    @property (class, nonatomic, assign, readonly) CGFloat fw_deviceWidth NS_REFINED_FOR_SWIFT;
    /// 设备高度,跟横竖屏无关
    @property (class, nonatomic, assign, readonly) CGFloat fw_deviceHeight NS_REFINED_FOR_SWIFT;
    /// 设备分辨率,跟横竖屏无关
    @property (class, nonatomic, assign, readonly) CGSize fw_deviceResolution NS_REFINED_FOR_SWIFT;
    
    @end

UIScreen+FWAdaptive

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIScreen (FWAdaptive)
    
    /// 屏幕尺寸
    @property (class, nonatomic, assign, readonly) CGSize fw_screenSize NS_REFINED_FOR_SWIFT;
    /// 屏幕宽度
    @property (class, nonatomic, assign, readonly) CGFloat fw_screenWidth NS_REFINED_FOR_SWIFT;
    /// 屏幕高度
    @property (class, nonatomic, assign, readonly) CGFloat fw_screenHeight NS_REFINED_FOR_SWIFT;
    /// 屏幕像素比例
    @property (class, nonatomic, assign, readonly) CGFloat fw_screenScale NS_REFINED_FOR_SWIFT;
    /// 是否是指定英寸屏幕
    + (BOOL)fw_isScreenInch:(FWScreenInch)inch NS_REFINED_FOR_SWIFT;
    /// 是否是全面屏屏幕
    @property (class, nonatomic, assign, readonly) BOOL fw_isNotchedScreen NS_REFINED_FOR_SWIFT;
    
    /// 获取一像素的大小
    @property (class, nonatomic, assign, readonly) CGFloat fw_pixelOne NS_REFINED_FOR_SWIFT;
    /// 检查是否含有安全区域,可用来判断iPhoneX
    @property (class, nonatomic, assign, readonly) BOOL fw_hasSafeAreaInsets NS_REFINED_FOR_SWIFT;
    /// 获取安全区域距离
    @property (class, nonatomic, assign, readonly) UIEdgeInsets fw_safeAreaInsets NS_REFINED_FOR_SWIFT;
    
    /// 状态栏高度,与是否隐藏无关
    @property (class, nonatomic, assign, readonly) CGFloat fw_statusBarHeight NS_REFINED_FOR_SWIFT;
    /// 导航栏高度,与是否隐藏无关
    @property (class, nonatomic, assign, readonly) CGFloat fw_navigationBarHeight NS_REFINED_FOR_SWIFT;
    /// 顶部栏高度,包含状态栏、导航栏,与是否隐藏无关
    @property (class, nonatomic, assign, readonly) CGFloat fw_topBarHeight NS_REFINED_FOR_SWIFT;
    /// 标签栏高度,与是否隐藏无关
    @property (class, nonatomic, assign, readonly) CGFloat fw_tabBarHeight NS_REFINED_FOR_SWIFT;
    /// 工具栏高度,与是否隐藏无关
    @property (class, nonatomic, assign, readonly) CGFloat fw_toolBarHeight NS_REFINED_FOR_SWIFT;
    
    /// 指定等比例缩放参考设计图尺寸,默认{375,812},宽度常用
    @property (class, nonatomic, assign) CGSize fw_referenceSize NS_REFINED_FOR_SWIFT;
    /// 获取当前屏幕宽度缩放比例,宽度常用
    @property (class, nonatomic, assign, readonly) CGFloat fw_relativeScale NS_REFINED_FOR_SWIFT;
    /// 获取当前屏幕高度缩放比例,高度不常用
    @property (class, nonatomic, assign, readonly) CGFloat fw_relativeHeightScale NS_REFINED_FOR_SWIFT;
    
    /// 获取相对设计图宽度等比例缩放值
    + (CGFloat)fw_relativeValue:(CGFloat)value NS_REFINED_FOR_SWIFT;
    
    /// 获取相对设计图高度等比例缩放值
    + (CGFloat)fw_relativeHeight:(CGFloat)value NS_REFINED_FOR_SWIFT;
    
    /// 获取相对设计图宽度等比例缩放时的固定宽度值
    + (CGFloat)fw_fixedValue:(CGFloat)value NS_REFINED_FOR_SWIFT;
    
    /// 获取相对设计图高度等比例缩放时的固定高度值
    + (CGFloat)fw_fixedHeight:(CGFloat)value NS_REFINED_FOR_SWIFT;
    
    /// 基于当前设备的屏幕倍数,对传进来的floatValue进行像素取整
    + (CGFloat)fw_flatValue:(CGFloat)value NS_REFINED_FOR_SWIFT;
    
    /// 基于指定的倍数(0取当前设备),对传进来的floatValue进行像素取整
    + (CGFloat)fw_flatValue:(CGFloat)value scale:(CGFloat)scale NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSObject (FWAppearance)
    
    /// 从 appearance 里取值并赋值给当前实例,通常在对象的 init 里调用
    - (void)fw_applyAppearance NS_REFINED_FOR_SWIFT;
    
    @end

UINavigationBar+FWBarAppearance

  • 导航栏视图分类,全局设置用[UINavigationBar appearance]。默认iOS15+启用appearance,iOS14及以下使用旧版本api

    See more

    Declaration

    Objective-C

    @interface UINavigationBar (FWBarAppearance)

UITabBar+FWBarAppearance

  • 标签栏视图分类,全局设置用[UITabBar appearance]。iOS15+启用appearance,iOS14及以下使用旧版本api

    See more

    Declaration

    Objective-C

    @interface UITabBar (FWBarAppearance)

UIToolbar+FWBarAppearance

  • 工具栏样式分类,全局设置用[UIToolbar appearance]。iOS15+启用appearance,iOS14及以下使用旧版本api

    Note

    工具栏高度建议用sizeToFit自动获取(示例44),contentView为内容视图(示例44),backgroundView为背景视图(示例78)
    See more

    Declaration

    Objective-C

    @interface UIToolbar (FWBarAppearance)

NSTimer+FWBlock

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSTimer (FWBlock)
    
    /**
     创建NSTimer,使用target-action,自动CommonModes添加到当前的运行循环中,避免ScrollView滚动时不触发
     
     @param seconds 时间
     @param target 目标
     @param selector 方法
     @param userInfo 参数
     @param repeats 是否重复
     @return 定时器
     */
    + (NSTimer *)fw_commonTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)selector userInfo:(nullable id)userInfo repeats:(BOOL)repeats NS_REFINED_FOR_SWIFT;
    
    /**
     创建NSTimer,使用block,自动CommonModes添加到当前的运行循环中,避免ScrollView滚动时不触发
     
     @param seconds 时间
     @param block 代码块
     @param repeats 是否重复
     @return 定时器
     */
    + (NSTimer *)fw_commonTimerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats NS_REFINED_FOR_SWIFT;
    
    /**
     创建倒计时定时器
     
     @param seconds 倒计时描述
     @param block 每秒执行block,为0时自动停止
     @return 定时器,可手工停止
     */
    + (NSTimer *)fw_commonTimerWithCountDown:(NSInteger)seconds block:(void (^)(NSInteger countDown))block NS_REFINED_FOR_SWIFT;
    
    /**
     创建NSTimer,使用block,需要调用addTimer:forMode:安排到当前的运行循环中(CommonModes避免ScrollView滚动时不触发)。
     @note 示例:[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]
     
     @param seconds 时间
     @param block 代码块
     @param repeats 是否重复
     @return 定时器
     */
    + (NSTimer *)fw_timerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats NS_REFINED_FOR_SWIFT;
    
    /**
     创建NSTimer,使用block,默认模式安排到当前的运行循环中
     
     @param seconds 时间
     @param block 代码块
     @param repeats 是否重复
     @return 定时器
     */
    + (NSTimer *)fw_scheduledTimerWithTimeInterval:(NSTimeInterval)seconds block:(void (^)(NSTimer *timer))block repeats:(BOOL)repeats NS_REFINED_FOR_SWIFT;
    
    /// 暂停NSTimer
    - (void)fw_pauseTimer NS_REFINED_FOR_SWIFT;
    
    /// 开始NSTimer
    - (void)fw_resumeTimer NS_REFINED_FOR_SWIFT;
    
    /// 延迟delay秒后开始NSTimer
    - (void)fw_resumeTimerAfterDelay:(NSTimeInterval)delay NS_REFINED_FOR_SWIFT;
    
    @end

UIGestureRecognizer+FWBlock

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIGestureRecognizer (FWBlock)
    
    /// 添加事件句柄,返回唯一标志
    - (NSString *)fw_addBlock:(void (^)(id sender))block NS_REFINED_FOR_SWIFT;
    
    /// 根据唯一标志移除事件句柄
    - (void)fw_removeBlock:(nullable NSString *)identifier NS_REFINED_FOR_SWIFT;
    
    /// 移除所有事件句柄
    - (void)fw_removeAllBlocks NS_REFINED_FOR_SWIFT;
    
    /// 从事件句柄初始化
    + (instancetype)fw_gestureRecognizerWithBlock:(void (^)(id sender))block NS_REFINED_FOR_SWIFT;
    
    @end

UIControl+FWBlock

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIControl (FWBlock)
    
    /// 添加事件句柄
    - (NSString *)fw_addBlock:(void (^)(id sender))block forControlEvents:(UIControlEvents)controlEvents NS_REFINED_FOR_SWIFT;
    
    /// 根据唯一标志移除事件句柄
    - (void)fw_removeBlock:(nullable NSString *)identifier forControlEvents:(UIControlEvents)controlEvents NS_REFINED_FOR_SWIFT;
    
    /// 移除所有事件句柄
    - (void)fw_removeAllBlocksForControlEvents:(UIControlEvents)controlEvents NS_REFINED_FOR_SWIFT;
    
    /// 添加点击事件
    - (void)fw_addTouchTarget:(id)target action:(SEL)action NS_REFINED_FOR_SWIFT;
    
    /// 添加点击句柄
    - (NSString *)fw_addTouchBlock:(void (^)(id sender))block NS_REFINED_FOR_SWIFT;
    
    /// 根据唯一标志移除点击句柄
    - (void)fw_removeTouchBlock:(nullable NSString *)identifier NS_REFINED_FOR_SWIFT;
    
    /// 移除所有点击句柄
    - (void)fw_removeAllTouchBlocks NS_REFINED_FOR_SWIFT;
    
    @end

UIBarButtonItem+FWBlock

  • iOS11之后,customView必须具有intrinsicContentSize值才能点击,可使用frame布局或者实现intrinsicContentSize即可

    See more

    Declaration

    Objective-C

    @interface UIBarButtonItem (FWBlock)

NSString+FWEncode

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSString (FWEncode)
    
    #pragma mark - Json
    
    /**
     Foundation对象编码为json字符串
     
     @param object 编码对象
     @return json字符串
     */
    + (nullable NSString *)fw_jsonEncode:(id)object NS_REFINED_FOR_SWIFT;
    
    /**
     *  json字符串解码为Foundation对象
     *
     *  @return Foundation对象
     */
    - (nullable id)fw_jsonDecode NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Base64
    
    /**
     *  base64编码
     *
     *  @return base64字符串
     */
    - (nullable NSString *)fw_base64Encode NS_REFINED_FOR_SWIFT;
    
    /**
     *  base64解码
     *
     *  @return 原字符串
     */
    - (nullable NSString *)fw_base64Decode NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Unicode
    
    /**
     *  计算长度,中文为1,英文为0.5
     */
    - (NSUInteger)fw_unicodeLength NS_REFINED_FOR_SWIFT;
    
    /**
     *  截取字符串,中文为1,英文为0.5
     *
     *  @param length 截取长度
     */
    - (NSString *)fw_unicodeSubstring:(NSUInteger)length NS_REFINED_FOR_SWIFT;
    
    /**
     *  Unicode中文编码,将中文转换成Unicode字符串(如\u7E8C)
     *
     *  @return Unicode字符串
     */
    - (NSString *)fw_unicodeEncode NS_REFINED_FOR_SWIFT;
    
    /**
     *  Unicode中文解码,将Unicode字符串(如\u7E8C)转换成中文
     *
     *  @return 中文字符串
     */
    - (NSString *)fw_unicodeDecode NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Url
    
    /**
     *  url参数编码,适用于query参数编码
     *  示例:http://test.com?id=我是中文 =>
     *       http%3A%2F%2Ftest.com%3Fid%3D%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87
     *
     *  @return url编码字符串
     */
    - (nullable NSString *)fw_urlEncodeComponent NS_REFINED_FOR_SWIFT;
    
    /**
     *  url参数解码,适用于query参数解码
     *  示例:http%3A%2F%2Ftest.com%3Fid%3D%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 =>
     *       http://test.com?id=我是中文
     *
     *  @return 原字符串
     */
    - (nullable NSString *)fw_urlDecodeComponent NS_REFINED_FOR_SWIFT;
    
    /**
     *  url编码,适用于整个url编码
     *  示例:http://test.com?id=我是中文 =>
     *       http://test.com?id=%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87
     *
     *  @return url编码地址
     */
    - (nullable NSString *)fw_urlEncode NS_REFINED_FOR_SWIFT;
    
    /**
     *  url解码,适用于整个url解码
     *  示例:http://test.com?id=%E6%88%91%E6%98%AF%E4%B8%AD%E6%96%87 =>
     *       http://test.com?id=我是中文
     *
     *  @return 原url地址
     */
    - (nullable NSString *)fw_urlDecode NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Query
    
    /**
     * 字典编码为URL参数字符串
     */
    + (NSString *)fw_queryEncode:(NSDictionary<NSString *, id> *)dictionary NS_REFINED_FOR_SWIFT;
    
    /**
     * URL参数字符串解码为字典,支持完整URL
     */
    - (NSDictionary<NSString *, NSString *> *)fw_queryDecode NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Md5
    
    /**
     *  md5编码
     *
     *  @return md5字符串
     */
    - (NSString *)fw_md5Encode NS_REFINED_FOR_SWIFT;
    
    /**
     *  文件md5编码
     *
     *  @return md5字符串
     */
    - (nullable NSString *)fw_md5EncodeFile NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Helper
    
    /**
     去掉空白字符
     */
    @property (nonatomic, copy, readonly) NSString *fw_trimString NS_REFINED_FOR_SWIFT;
    
    /**
     首字母大写
     */
    @property (nonatomic, copy, readonly) NSString *fw_ucfirstString NS_REFINED_FOR_SWIFT;
    
    /**
     首字母小写
     */
    @property (nonatomic, copy, readonly) NSString *fw_lcfirstString NS_REFINED_FOR_SWIFT;
    
    /**
     驼峰转下划线
     */
    @property (nonatomic, copy, readonly) NSString *fw_underlineString NS_REFINED_FOR_SWIFT;
    
    /**
     下划线转驼峰
     */
    @property (nonatomic, copy, readonly) NSString *fw_camelString NS_REFINED_FOR_SWIFT;
    
    /**
     中文转拼音
     */
    @property (nonatomic, copy, readonly) NSString *fw_pinyinString NS_REFINED_FOR_SWIFT;
    
    /**
     过滤JSON解码特殊字符
     
     兼容\uD800-\uDFFF引起JSON解码报错3840问题,不报错时无需调用
     规则:只允许以\uD800-\uDBFF高位开头,紧跟\uDC00-\uDFFF低位;其他全不允许
     参考:https://github.com/SBJson/SBJson/blob/trunk/Classes/SBJson5StreamTokeniser.m
     */
    @property (nonatomic, copy, readonly) NSString *fw_escapeJson NS_REFINED_FOR_SWIFT;
    
    /**
     转换为UTF8编码数据
     */
    @property (nonatomic, strong, readonly, nullable) NSData *fw_utf8Data NS_REFINED_FOR_SWIFT;
    
    /**
     转换为NSURL
     */
    @property (nonatomic, copy, readonly, nullable) NSURL *fw_url NS_REFINED_FOR_SWIFT;
    
    /**
     转换为NSNumber
     */
    @property (nonatomic, readonly, nullable) NSNumber *fw_number NS_REFINED_FOR_SWIFT;
    
    @end

NSData+FWEncode

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSData (FWEncode)
    
    #pragma mark - Json
    
    /**
     Foundation对象编码为json数据
     
     @param object 编码对象
     @return json数据
     */
    + (nullable NSData *)fw_jsonEncode:(id)object NS_REFINED_FOR_SWIFT;
    
    /**
     json数据解码为Foundation对象
    
     @return Foundation对象
     */
    - (nullable id)fw_jsonDecode NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Base64
    
    /**
     *  base64编码
     *
     *  @return base64数据
     */
    - (NSData *)fw_base64Encode NS_REFINED_FOR_SWIFT;
    
    /**
     *  base64解码
     *
     *  @return 原数据
     */
    - (nullable NSData *)fw_base64Decode NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Helper
    
    /**
     转换为UTF8编码字符串
     
     @return UTF8编码字符串
     */
    @property (nonatomic, copy, readonly, nullable) NSString *fw_utf8String NS_REFINED_FOR_SWIFT;
    
    @end

NSURL+FWEncode

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSURL (FWEncode)
    
    /// 获取当前query的参数字典,不含空值
    @property (nonatomic, copy, readonly) NSDictionary<NSString *, NSString *> *fw_queryDictionary NS_REFINED_FOR_SWIFT;
    
    /// 获取基准URI字符串,不含path|query|fragment等,包含scheme|host|port等
    @property (nonatomic, copy, readonly, nullable) NSString *fw_baseURI NS_REFINED_FOR_SWIFT;
    
    /// 获取路径URI字符串,不含scheme|host|port等,包含path|query|fragment等
    @property (nonatomic, copy, readonly, nullable) NSString *fw_pathURI NS_REFINED_FOR_SWIFT;
    
    /// 生成URL,中文自动URL编码
    + (nullable NSURL *)fw_urlWithString:(nullable NSString *)string NS_REFINED_FOR_SWIFT;
    
    /// 生成URL,中文自动URL编码
    + (nullable NSURL *)fw_urlWithString:(nullable NSString *)string relativeTo:(nullable NSURL *)baseURL NS_REFINED_FOR_SWIFT;
    
    @end

NSObject+FWSafeType

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSObject (FWSafeType)
    
    /**
     是否是非Null(nil, NSNull)
     
     @return 如果为非Null返回YES,为Null返回NO
     */
    @property (nonatomic, assign, readonly) BOOL fw_isNotNull NS_REFINED_FOR_SWIFT;
    
    /**
     是否是非空对象(nil, NSNull, count为0, length为0)
     
     @return 如果是非空对象返回YES,为空对象返回NO
     */
    @property (nonatomic, assign, readonly) BOOL fw_isNotEmpty NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为NSInteger
     
     @return NSInteger
     */
    @property (nonatomic, assign, readonly) NSInteger fw_safeInteger NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为Float
     
     @return Float
     */
    @property (nonatomic, assign, readonly) float fw_safeFloat NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为Double
     
     @return Double
     */
    @property (nonatomic, assign, readonly) double fw_safeDouble NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为Bool
     
     @return Bool
     */
    @property (nonatomic, assign, readonly) BOOL fw_safeBool NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为NSNumber
     
     @return NSNumber
     */
    @property (nonatomic, strong, readonly) NSNumber *fw_safeNumber NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为NSString
     
     @return NSString
     */
    @property (nonatomic, copy, readonly) NSString *fw_safeString NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为NSDate
     
     @return NSDate
     */
    @property (nonatomic, strong, readonly) NSDate *fw_safeDate NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为NSData
     
     @return NSData
     */
    @property (nonatomic, strong, readonly) NSData *fw_safeData NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为NSArray
     
     @return NSArray
     */
    @property (nonatomic, strong, readonly) NSArray *fw_safeArray NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为NSMutableArray
     
     @return NSMutableArray
     */
    @property (nonatomic, strong, readonly) NSMutableArray *fw_safeMutableArray NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为NSDictionary
     
     @return NSDictionary
     */
    @property (nonatomic, strong, readonly) NSDictionary *fw_safeDictionary NS_REFINED_FOR_SWIFT;
    
    /**
     检测并安全转换为NSMutableDictionary
     
     @return NSMutableDictionary
     */
    @property (nonatomic, strong, readonly) NSMutableDictionary *fw_safeMutableDictionary NS_REFINED_FOR_SWIFT;
    
    @end

NSString+FWSafeType

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSString (FWSafeType)
    
    /**
     从指定位置截取子串
     
     @param from 起始位置
     @return 子串
     */
    - (nullable NSString *)fw_substringFromIndex:(NSInteger)from NS_REFINED_FOR_SWIFT;
    
    /**
     截取子串到指定位置
     
     @param to 结束位置
     @return 子串
     */
    - (nullable NSString *)fw_substringToIndex:(NSInteger)to NS_REFINED_FOR_SWIFT;
    
    /**
     截取指定范围的子串
     
     @param range 指定范围
     @return 子串
     */
    - (nullable NSString *)fw_substringWithRange:(NSRange)range NS_REFINED_FOR_SWIFT;
    
    @end

NSArray+FWSafeType

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSArray<__covariant ObjectType> (FWSafeType)
    
    /**
     安全获取对象
     
     @param index 索引
     @return 对象
     */
    - (nullable ObjectType)fw_objectAtIndex:(NSInteger)index NS_REFINED_FOR_SWIFT;
    
    /**
     安全获取子数组
     
     @param range 范围
     @return 对象数组
     */
    - (nullable NSArray<ObjectType> *)fw_subarrayWithRange:(NSRange)range NS_REFINED_FOR_SWIFT;
    
    @end

NSMutableArray+FWSafeType

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSMutableArray<ObjectType> (FWSafeType)
    
    /**
     安全添加对象
     
     @param object 对象
     */
    - (void)fw_addObject:(nullable ObjectType)object NS_REFINED_FOR_SWIFT;
    
    /**
     安全移除指定索引对象
     
     @param index 索引
     */
    - (void)fw_removeObjectAtIndex:(NSInteger)index NS_REFINED_FOR_SWIFT;
    
    /**
     安全插入对象到指定位置
     
     @param object 对象
     @param index 索引
     */
    - (void)fw_insertObject:(nullable ObjectType)object atIndex:(NSInteger)index NS_REFINED_FOR_SWIFT;
    
    /**
     安全替换对象到指定位置
     
     @param index 索引
     @param object 对象
     */
    - (void)fw_replaceObjectAtIndex:(NSInteger)index withObject:(nullable ObjectType)object NS_REFINED_FOR_SWIFT;
    
    /**
     安全移除子数组
     
     @param range 范围
     */
    - (void)fw_removeObjectsInRange:(NSRange)range NS_REFINED_FOR_SWIFT;
    
    /**
     安全插入数组到指定位置
     
     @param objects 要插入的数组
     @param index 索引
     */
    - (void)fw_insertObjects:(nullable NSArray *)objects atIndex:(NSInteger)index NS_REFINED_FOR_SWIFT;
    
    @end

NSMutableSet+FWSafeType

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSMutableSet<ObjectType> (FWSafeType)
    
    /**
     安全添加对象
     
     @param object 对象
     */
    - (void)fw_addObject:(nullable ObjectType)object NS_REFINED_FOR_SWIFT;
    
    /**
     安全移除对象
     
     @param object 对象
     */
    - (void)fw_removeObject:(nullable ObjectType)object NS_REFINED_FOR_SWIFT;
    
    @end

NSDictionary+FWSafeType

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSDictionary<__covariant KeyType, __covariant ObjectType> (FWSafeType)
    
    /**
     安全读取对象(过滤NSNull)
     
     @param key 键名
     @return 键值
     */
    - (nullable ObjectType)fw_objectForKey:(nullable KeyType)key NS_REFINED_FOR_SWIFT;
    
    @end

NSMutableDictionary+FWSafeType

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSMutableDictionary<KeyType, ObjectType> (FWSafeType)
    
    /**
     安全移除指定键名
     
     @param key 键名
     */
    - (void)fw_removeObjectForKey:(nullable KeyType)key NS_REFINED_FOR_SWIFT;
    
    /**
     安全设置对象(过滤NSNull)
    
     @param object 键值
     @param key 键名
     */
    - (void)fw_setObject:(nullable ObjectType)object forKey:(nullable KeyType <NSCopying>)key NS_REFINED_FOR_SWIFT;
    
    @end

NSArray+FWFoundation

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSArray<__covariant ObjectType> (FWFoundation)
    
    /// 过滤数组元素,返回YES的obj重新组装成一个数组
    - (NSArray<ObjectType> *)fw_filterWithBlock:(BOOL (^)(ObjectType obj))block NS_REFINED_FOR_SWIFT;
    
    /// 映射数组元素,返回的obj重新组装成一个数组
    - (NSArray *)fw_mapWithBlock:(id _Nullable (^)(ObjectType obj))block NS_REFINED_FOR_SWIFT;
    
    /// 匹配数组第一个元素,返回满足条件的第一个obj
    - (nullable ObjectType)fw_matchWithBlock:(BOOL (^)(ObjectType obj))block NS_REFINED_FOR_SWIFT;
    
    /// 从数组中随机取出对象,如@[@"a", @"b", @"c"]随机取出@"b"
    @property (nullable, nonatomic, readonly) ObjectType fw_randomObject NS_REFINED_FOR_SWIFT;
    
    @end

NSAttributedString+FWFoundation

  • 如果需要实现行内图片可点击效果,可使用UITextView添加附件或Link并实现delegate.shouldInteractWith方法即可

    See more

    Declaration

    Objective-C

    @interface NSAttributedString (FWFoundation)

NSData+FWFoundation

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSData (FWFoundation)
    
    /// 使用NSKeyedUnarchiver解压数据
    - (nullable id)fw_unarchiveObject:(Class)clazz NS_REFINED_FOR_SWIFT;
    
    /// 使用NSKeyedArchiver压缩对象
    + (nullable NSData *)fw_archiveObject:(id)object NS_REFINED_FOR_SWIFT;
    
    /// 保存对象归档
    + (BOOL)fw_archiveObject:(id)object toFile:(NSString *)path NS_REFINED_FOR_SWIFT;
    
    /// 读取对象归档
    + (nullable id)fw_unarchiveObject:(Class)clazz withFile:(NSString *)path NS_REFINED_FOR_SWIFT;
    
    @end

NSDate+FWFoundation

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSDate (FWFoundation)
    
    /// 转化为字符串,默认当前时区,格式:yyyy-MM-dd HH:mm:ss
    @property (nonatomic, copy, readonly) NSString *fw_stringValue NS_REFINED_FOR_SWIFT;
    
    /// 转化为字符串,默认当前时区,自定义格式
    - (NSString *)fw_stringWithFormat:(NSString *)format NS_REFINED_FOR_SWIFT;
    
    /// 转化为字符串,自定义格式和时区
    - (NSString *)fw_stringWithFormat:(NSString *)format timeZone:(nullable NSTimeZone *)timeZone NS_REFINED_FOR_SWIFT;
    
    /// 当前时间戳,没有设置过返回本地时间戳,可同步设置服务器时间戳,同步后调整手机时间不影响
    @property (class, nonatomic, assign) NSTimeInterval fw_currentTime NS_REFINED_FOR_SWIFT;
    
    /// 从字符串初始化日期,默认当前时区,格式:yyyy-MM-dd HH:mm:ss
    + (nullable NSDate *)fw_dateWithString:(NSString *)string NS_REFINED_FOR_SWIFT;
    
    /// 从字符串初始化日期,默认当前时区,自定义格式
    + (nullable NSDate *)fw_dateWithString:(NSString *)string format:(NSString *)format NS_REFINED_FOR_SWIFT;
    
    /// 从字符串初始化日期,自定义格式和时区
    + (nullable NSDate *)fw_dateWithString:(NSString *)string format:(NSString *)format timeZone:(nullable NSTimeZone *)timeZone NS_REFINED_FOR_SWIFT;
    
    /// 格式化时长,格式"00:00"或"00:00:00"
    + (NSString *)fw_formatDuration:(NSTimeInterval)duration hasHour:(BOOL)hasHour NS_REFINED_FOR_SWIFT;
    
    /// 格式化16位、13位时间戳为10位(秒)
    + (NSTimeInterval)fw_formatTimestamp:(NSTimeInterval)timestamp NS_REFINED_FOR_SWIFT;
    
    @end

NSDictionary+FWFoundation

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSDictionary<__covariant KeyType, __covariant ObjectType> (FWFoundation)
    
    /// 过滤字典元素,如果block返回NO,则去掉该元素
    - (NSDictionary<KeyType, ObjectType> *)fw_filterWithBlock:(BOOL (^)(KeyType key, ObjectType obj))block NS_REFINED_FOR_SWIFT;
    
    /// 映射字典元素,返回的obj重新组装成一个字典
    - (NSDictionary *)fw_mapWithBlock:(id _Nullable (^)(KeyType key, ObjectType obj))block NS_REFINED_FOR_SWIFT;
    
    /// 匹配字典第一个元素,返回满足条件的第一个obj
    - (nullable ObjectType)fw_matchWithBlock:(BOOL (^)(KeyType key, ObjectType obj))block NS_REFINED_FOR_SWIFT;
    
    @end

NSObject+FWFoundation

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSObject (FWFoundation)
    
    /// 执行加锁(支持任意对象),等待信号量,自动创建信号量
    - (void)fw_lock NS_REFINED_FOR_SWIFT;
    
    /// 执行解锁(支持任意对象),发送信号量,自动创建信号量
    - (void)fw_unlock NS_REFINED_FOR_SWIFT;
    
    @end

NSString+FWFoundation

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSString (FWFoundation)
    
    /// 计算单行字符串指定字体所占尺寸
    - (CGSize)fw_sizeWithFont:(UIFont *)font NS_REFINED_FOR_SWIFT;
    
    /// 计算多行字符串指定字体在指定绘制区域内所占尺寸
    - (CGSize)fw_sizeWithFont:(UIFont *)font drawSize:(CGSize)drawSize NS_REFINED_FOR_SWIFT;
    
    /// 计算多行字符串指定字体、指定属性在指定绘制区域内所占尺寸
    - (CGSize)fw_sizeWithFont:(UIFont *)font drawSize:(CGSize)drawSize attributes:(nullable NSDictionary<NSAttributedStringKey, id> *)attributes NS_REFINED_FOR_SWIFT;
    
    /// 是否匹配正则表达式,示例:^[a-zA-Z0-9_\u4e00-\u9fa5]{4,14}$
    - (BOOL)fw_matchesRegex:(NSString *)regex NS_REFINED_FOR_SWIFT;
    
    /// 格式化文件大小为".0K/.1M/.1G"
    + (NSString *)fw_sizeString:(NSUInteger)fileSize NS_REFINED_FOR_SWIFT;
    
    @end

NSUserDefaults+FWFoundation

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSUserDefaults (FWFoundation)
    
    /// 读取对象,支持unarchive对象
    - (nullable id)fw_objectForKey:(NSString *)key NS_REFINED_FOR_SWIFT;
    
    /// 保存对象,支持archive对象
    - (void)fw_setObject:(nullable id)object forKey:(NSString *)key NS_REFINED_FOR_SWIFT;
    
    /// 从standard读取对象,支持unarchive对象
    + (nullable id)fw_objectForKey:(NSString *)key NS_REFINED_FOR_SWIFT;
    
    /// 保存对象到standard,支持archive对象
    + (void)fw_setObject:(nullable id)object forKey:(NSString *)key NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface FWAutoloader (FWFramework_Swift_383)
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface FWAutoloader (FWFramework_Swift_391)
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface FWPromise (FWFramework_Swift_521)
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIDevice (SWIFT_EXTENSION(FWFramework))
    /// 获取或设置设备UUID,自动keychain持久化。默认获取IDFV(未使用IDFA,避免额外权限),失败则随机生成一个
    SWIFT_CLASS_PROPERTY(@property (nonatomic, class, copy) NSString * _Nonnull fw_deviceUUID;)
    + (NSString * _Nonnull)fw_deviceUUID SWIFT_WARN_UNUSED_RESULT;
    + (void)setFw_deviceUUID:(NSString * _Nonnull)newValue;
    @end

UITextField+FWKeyboard

NSBundle+FWLanguage

  • NSBundle系统语言分类,处理mainBundle语言。如果需要处理三方SDK和系统组件语言,详见Bundle分类

    Note

    如果系统组件无法正确显示语言,需Info.plist设置CFBundleAllowMixedLocalizations为YES,从而允许应用程序获取框架库内语言。 如果key为nil,value为nil,返回空串;key为nil,value非nil,返回value;如果key不存在,value为nil或空,返回key;如果key不存在,value非空,返回value 当前使用修改bundle类方式实现,也可以使用动态替换localizedStringForKey方法来实现,但需注意此方式的性能
    See more

    Declaration

    Objective-C

    @interface NSBundle (FWLanguage)

NSString+FWLanguage

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSString (FWLanguage)
    
    /// 快速读取本地化语言
    @property (nonatomic, copy, readonly) NSString *fw_localized NS_REFINED_FOR_SWIFT;
    
    @end

NSObject+FWMessage

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSObject (FWMessage)
    
    #pragma mark - Observer
    
    /**
     监听某个点对点消息,对象释放时自动移除监听,添加多次执行多次
     
     @param name  消息名称
     @param block 消息句柄
     @return 监听唯一标志
     */
    - (NSString *)fw_observeMessage:(NSNotificationName)name block:(void (^)(NSNotification *notification))block NS_REFINED_FOR_SWIFT;
    
    /**
     监听某个指定对象点对点消息,对象释放时自动移除监听,添加多次执行多次
     
     @param name   消息名称
     @param object 消息对象,值为nil时表示所有
     @param block  消息句柄
     @return 监听唯一标志
     */
    - (NSString *)fw_observeMessage:(NSNotificationName)name object:(nullable id)object block:(void (^)(NSNotification *notification))block NS_REFINED_FOR_SWIFT;
    
    /**
     监听某个点对点消息,对象释放时自动移除监听,添加多次执行多次
     
     @param name   消息名称
     @param target 消息目标
     @param action 目标动作,参数为通知对象
     @return 监听唯一标志
     */
    - (NSString *)fw_observeMessage:(NSNotificationName)name target:(nullable id)target action:(SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     监听某个指定对象点对点消息,对象释放时自动移除监听,添加多次执行多次
     
     @param name   消息名称
     @param object 消息对象,值为nil时表示所有
     @param target 消息目标
     @param action 目标动作,参数为通知对象
     @return 监听唯一标志
     */
    - (NSString *)fw_observeMessage:(NSNotificationName)name object:(nullable id)object target:(nullable id)target action:(SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个点对点消息指定监听
     
     @param name   消息名称
     @param target 消息目标
     @param action 目标动作
     */
    - (void)fw_unobserveMessage:(NSNotificationName)name target:(nullable id)target action:(nullable SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个指定对象点对点消息指定监听
     
     @param name   消息名称
     @param object 消息对象,值为nil时表示所有
     @param target 消息目标
     @param action 目标动作
     */
    - (void)fw_unobserveMessage:(NSNotificationName)name object:(nullable id)object target:(nullable id)target action:(nullable SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个指定对象点对点消息指定监听
     
     @param name       消息名称
     @param identifier 监听唯一标志
     */
    - (void)fw_unobserveMessage:(NSNotificationName)name identifier:(NSString *)identifier NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个点对点消息所有监听
     
     @param name 消息名称
     */
    - (void)fw_unobserveMessage:(NSNotificationName)name NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个指定对象点对点消息所有监听
     
     @param name   消息名称
     @param object 消息对象,值为nil时表示所有
     */
    - (void)fw_unobserveMessage:(NSNotificationName)name object:(nullable id)object NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除所有点对点消息监听
     */
    - (void)fw_unobserveAllMessages NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Subject
    
    /**
     发送点对点消息
     
     @param name 消息名称
     @param receiver 消息接收者
     */
    - (void)fw_sendMessage:(NSNotificationName)name toReceiver:(id)receiver NS_REFINED_FOR_SWIFT;
    
    /**
     发送点对点消息,附带对象
     
     @param name   消息名称
     @param object 消息对象
     @param receiver 消息接收者
     */
    - (void)fw_sendMessage:(NSNotificationName)name object:(nullable id)object toReceiver:(id)receiver NS_REFINED_FOR_SWIFT;
    
    /**
     发送点对点消息,附带对象和用户信息
     
     @param name     消息名称
     @param object   消息对象
     @param userInfo 用户信息
     @param receiver 消息接收者
     */
    - (void)fw_sendMessage:(NSNotificationName)name object:(nullable id)object userInfo:(nullable NSDictionary *)userInfo toReceiver:(id)receiver NS_REFINED_FOR_SWIFT;
    
    /**
     发送类点对点消息
     
     @param name 消息名称
     @param receiver 消息接收者
     */
    + (void)fw_sendMessage:(NSNotificationName)name toReceiver:(id)receiver NS_REFINED_FOR_SWIFT;
    
    /**
     发送类点对点消息,附带对象
     
     @param name   消息名称
     @param object 消息对象
     @param receiver 消息接收者
     */
    + (void)fw_sendMessage:(NSNotificationName)name object:(nullable id)object toReceiver:(id)receiver NS_REFINED_FOR_SWIFT;
    
    /**
     发送类点对点消息,附带对象和用户信息
     
     @param name     消息名称
     @param object   消息对象
     @param userInfo 用户信息
     @param receiver 消息接收者
     */
    + (void)fw_sendMessage:(NSNotificationName)name object:(nullable id)object userInfo:(nullable NSDictionary *)userInfo toReceiver:(id)receiver NS_REFINED_FOR_SWIFT;
    
    @end

NSObject+FWNotification

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSObject (FWNotification)
    
    #pragma mark - Observer
    
    /**
     监听某个广播通知,对象释放时自动移除监听,添加多次执行多次
     
     @param name  通知名称
     @param block 通知句柄
     @return 监听唯一标志
     */
    - (NSString *)fw_observeNotification:(NSNotificationName)name block:(void (^)(NSNotification *notification))block NS_REFINED_FOR_SWIFT;
    
    /**
     监听某个指定对象广播通知,对象释放时自动移除监听,添加多次执行多次
     
     @param name   通知名称
     @param object 通知对象,值为nil时表示所有
     @param block  通知句柄
     @return 监听唯一标志
     */
    - (NSString *)fw_observeNotification:(NSNotificationName)name object:(nullable id)object block:(void (^)(NSNotification *notification))block NS_REFINED_FOR_SWIFT;
    
    /**
     监听某个广播通知,对象释放时自动移除监听,添加多次执行多次
     
     @param name   通知名称
     @param target 通知目标
     @param action 目标动作,参数为通知对象
     @return 监听唯一标志
     */
    - (NSString *)fw_observeNotification:(NSNotificationName)name target:(nullable id)target action:(SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     监听某个指定对象广播通知,对象释放时自动移除监听,添加多次执行多次
     
     @param name   通知名称
     @param object 通知对象,值为nil时表示所有
     @param target 通知目标
     @param action 目标动作,参数为通知对象
     @return 监听唯一标志
     */
    - (NSString *)fw_observeNotification:(NSNotificationName)name object:(nullable id)object target:(nullable id)target action:(SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个广播通知指定监听
     
     @param name   通知名称
     @param target 通知目标
     @param action 目标动作
     */
    - (void)fw_unobserveNotification:(NSNotificationName)name target:(nullable id)target action:(nullable SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个指定对象广播通知指定监听
     
     @param name   通知名称
     @param object 通知对象,值为nil时表示所有
     @param target 通知目标
     @param action 目标动作
     */
    - (void)fw_unobserveNotification:(NSNotificationName)name object:(nullable id)object target:(nullable id)target action:(nullable SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个指定对象广播通知指定监听
     
     @param name       通知名称
     @param identifier 监听唯一标志
     */
    - (void)fw_unobserveNotification:(NSNotificationName)name identifier:(NSString *)identifier NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个广播通知所有监听
     
     @param name 通知名称
     */
    - (void)fw_unobserveNotification:(NSNotificationName)name NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个指定对象广播通知所有监听
     
     @param name   通知名称
     @param object 通知对象,值为nil时表示所有
     */
    - (void)fw_unobserveNotification:(NSNotificationName)name object:(nullable id)object NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除所有广播通知监听
     */
    - (void)fw_unobserveAllNotifications NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Subject
    
    /**
     发送广播通知
     
     @param name 通知名称
     */
    - (void)fw_postNotification:(NSNotificationName)name NS_REFINED_FOR_SWIFT;
    
    /**
     发送广播通知,附带对象
     
     @param name   通知名称
     @param object 通知对象
     */
    - (void)fw_postNotification:(NSNotificationName)name object:(nullable id)object NS_REFINED_FOR_SWIFT;
    
    /**
     发送广播通知,附带对象和用户信息
     
     @param name     通知名称
     @param object   通知对象
     @param userInfo 用户信息
     */
    - (void)fw_postNotification:(NSNotificationName)name object:(nullable id)object userInfo:(nullable NSDictionary *)userInfo NS_REFINED_FOR_SWIFT;
    
    /**
     发送广播通知
     
     @param name 通知名称
     */
    + (void)fw_postNotification:(NSNotificationName)name NS_REFINED_FOR_SWIFT;
    
    /**
     发送广播通知,附带对象
     
     @param name   通知名称
     @param object 通知对象
     */
    + (void)fw_postNotification:(NSNotificationName)name object:(nullable id)object NS_REFINED_FOR_SWIFT;
    
    /**
     发送广播通知,附带对象和用户信息
     
     @param name     通知名称
     @param object   通知对象
     @param userInfo 用户信息
     */
    + (void)fw_postNotification:(NSNotificationName)name object:(nullable id)object userInfo:(nullable NSDictionary *)userInfo NS_REFINED_FOR_SWIFT;
    
    @end

NSObject+FWKvo

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSObject (FWKvo)
    
    /**
     监听对象某个属性,对象释放时自动移除监听,添加多次执行多次
     
     @param property 属性名称
     @param block    目标句柄,block参数依次为object、优化的change字典(不含NSNull)
     @return 监听唯一标志
     */
    - (NSString *)fw_observeProperty:(NSString *)property block:(void (^)(id object, NSDictionary<NSKeyValueChangeKey, id> *change))block NS_REFINED_FOR_SWIFT;
    
    /**
     监听对象某个属性,对象释放时自动移除监听,添加多次执行多次
     
     @param property 属性名称
     @param target   目标对象
     @param action   目标动作,action参数依次为object、优化的change字典(不含NSNull)
     @return 监听唯一标志
     */
    - (NSString *)fw_observeProperty:(NSString *)property target:(nullable id)target action:(SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个属性指定监听
     
     @param property 属性名称
     @param target   目标对象,值为nil时移除所有对象(同UIControl)
     @param action   目标动作,值为nil时移除所有动作(同UIControl)
     */
    - (void)fw_unobserveProperty:(NSString *)property target:(nullable id)target action:(nullable SEL)action NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个属性指定监听
     
     @param property   属性名称
     @param identifier 监听唯一标志
     */
    - (void)fw_unobserveProperty:(NSString *)property identifier:(NSString *)identifier NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除某个属性所有监听
     
     @param property 属性名称
     */
    - (void)fw_unobserveProperty:(NSString *)property NS_REFINED_FOR_SWIFT;
    
    /**
     手工移除所有属性所有监听
     */
    - (void)fw_unobserveAllProperties NS_REFINED_FOR_SWIFT;
    
    @end

UIWindow+FWNavigation

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIWindow (FWNavigation)
    
    /// 获取最顶部的视图控制器
    @property (nonatomic, readonly, nullable) UIViewController *fw_topViewController NS_REFINED_FOR_SWIFT;
    
    /// 获取最顶部的导航栏控制器。如果顶部VC不含导航栏,返回nil
    @property (nonatomic, readonly, nullable) UINavigationController *fw_topNavigationController NS_REFINED_FOR_SWIFT;
    
    /// 获取最顶部的显示控制器
    @property (nonatomic, readonly, nullable) UIViewController *fw_topPresentedController NS_REFINED_FOR_SWIFT;
    
    /// 使用最顶部的导航栏控制器打开控制器
    - (BOOL)fw_pushViewController:(UIViewController *)viewController animated:(BOOL)animated NS_REFINED_FOR_SWIFT;
    
    /// 使用最顶部的导航栏控制器打开控制器,同时pop指定数量控制器
    - (BOOL)fw_pushViewController:(UIViewController *)viewController pop:(NSUInteger)count animated:(BOOL)animated NS_REFINED_FOR_SWIFT;
    
    /// 使用最顶部的显示控制器弹出控制器,建议present导航栏控制器(可用来push)
    - (void)fw_presentViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// 使用最顶部的视图控制器打开控制器,自动判断push|present,完成时回调
    - (void)fw_openViewController:(UIViewController *)viewController animated:(BOOL)animated options:(FWNavigationOptions)options completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// 关闭最顶部的视图控制器,自动判断pop|dismiss,返回是否成功,完成时回调
    - (BOOL)fw_closeViewControllerAnimated:(BOOL)animated options:(FWNavigationOptions)options completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// 获取当前主window
    @property (class, nonatomic, readonly, nullable) UIWindow *fw_mainWindow NS_REFINED_FOR_SWIFT;
    
    /// 获取当前主场景
    @property (class, nonatomic, readonly, nullable) UIWindowScene *fw_mainScene API_AVAILABLE(ios(13.0)) NS_REFINED_FOR_SWIFT;
    
    /// 获取最顶部的视图控制器
    @property (class, nonatomic, readonly, nullable) UIViewController *fw_topViewController NS_REFINED_FOR_SWIFT;
    
    /// 获取最顶部的导航栏控制器。如果顶部VC不含导航栏,返回nil
    @property (class, nonatomic, readonly, nullable) UINavigationController *fw_topNavigationController NS_REFINED_FOR_SWIFT;
    
    /// 获取最顶部的显示控制器
    @property (class, nonatomic, readonly, nullable) UIViewController *fw_topPresentedController NS_REFINED_FOR_SWIFT;
    
    /// 使用最顶部的导航栏控制器打开控制器
    + (BOOL)fw_pushViewController:(UIViewController *)viewController animated:(BOOL)animated NS_REFINED_FOR_SWIFT;
    
    /// 使用最顶部的导航栏控制器打开控制器,同时pop指定数量控制器
    + (BOOL)fw_pushViewController:(UIViewController *)viewController pop:(NSUInteger)count animated:(BOOL)animated NS_REFINED_FOR_SWIFT;
    
    /// 使用最顶部的显示控制器弹出控制器,建议present导航栏控制器(可用来push)
    + (void)fw_presentViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// 使用最顶部的视图控制器打开控制器,自动判断push|present,完成时回调
    + (void)fw_openViewController:(UIViewController *)viewController animated:(BOOL)animated options:(FWNavigationOptions)options completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// 关闭最顶部的视图控制器,自动判断pop|dismiss,返回是否成功,完成时回调
    + (BOOL)fw_closeViewControllerAnimated:(BOOL)animated options:(FWNavigationOptions)options completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    @end

UINavigationController+FWNavigation

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UINavigationController (FWNavigation)
    
    #pragma mark - Navigation
    
    /// push新界面,完成时回调
    - (void)fw_pushViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// pop当前界面,完成时回调
    - (nullable UIViewController *)fw_popViewControllerAnimated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// pop到指定界面,完成时回调
    - (nullable NSArray<__kindof UIViewController *> *)fw_popToViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// pop到根界面,完成时回调
    - (nullable NSArray<__kindof UIViewController *> *)fw_popToRootViewControllerAnimated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// 设置界面数组,完成时回调
    - (void)fw_setViewControllers:(NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// push新界面,同时pop指定数量界面,至少保留一个根控制器,完成时回调
    - (void)fw_pushViewController:(UIViewController *)viewController pop:(NSUInteger)count animated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// pop指定数量界面,0不会pop,至少保留一个根控制器,完成时回调
    - (nullable NSArray<__kindof UIViewController *> *)fw_popViewControllers:(NSUInteger)count animated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Workflow
    
    /**
     当前最外层工作流名称,即topViewController的工作流名称
     
     @return 工作流名称
     */
    @property (nonatomic, copy, readonly, nullable) NSString *fw_topWorkflowName NS_REFINED_FOR_SWIFT;
    
    /**
     push控制器,并清理最外层工作流(不属于工作流则不清理),完成时回调
     @note 示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)、4、(5、6)、9
     
     @param viewController push的控制器
     @param animated 是否执行动画
     */
    - (void)fw_pushViewController:(UIViewController *)viewController popTopWorkflowAnimated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /**
     push控制器,并清理非根控制器(只保留根控制器),完成时回调
     @note 示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、9
     
     @param viewController push的控制器
     @param animated 是否执行动画
     */
    - (void)fw_pushViewController:(UIViewController *)viewController popToRootWorkflowAnimated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /**
     push控制器,并从外到内清理指定工作流,直到遇到不属于指定工作流的控制器停止,完成时回调
     @note 示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)、4、9
     
     @param viewController push的控制器
     @param workflows 指定工作流
     @param animated 是否执行动画
     */
    - (void)fw_pushViewController:(UIViewController *)viewController popWorkflows:(nullable NSArray<NSString *> *)workflows animated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /**
     pop方式清理最外层工作流,至少保留一个根控制器(不属于工作流则不清理),完成时回调
     @note 示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)、4、(5、6)
     
     @param animated 是否执行动画
     */
    - (void)fw_popTopWorkflowAnimated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /**
     pop方式从外到内清理指定工作流,直到遇到不属于指定工作流的控制器停止,至少保留一个根控制器,完成时回调
     @note 示例:1、(2、3)、4、(5、6)、(7、8),操作后为1、(2、3)、4
     
     @param workflows 指定工作流
     @param animated  是否执行动画
     */
    - (void)fw_popWorkflows:(nullable NSArray<NSString *> *)workflows animated:(BOOL)animated completion:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    @end

CADisplayLink+FWQuartzCore

  • 如果block参数不会被持有并后续执行,可声明为NS_NOESCAPE,不会触发循环引用

    See more

    Declaration

    Objective-C

    @interface CADisplayLink (FWQuartzCore)

CAAnimation+FWQuartzCore

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface CAAnimation (FWQuartzCore)
    
    /// 设置动画开始回调,需要在add之前添加,因为add时会自动拷贝一份对象
    @property (nonatomic, copy, nullable) void (^fw_startBlock)(CAAnimation *animation) NS_REFINED_FOR_SWIFT;
    
    /// 设置动画停止回调
    @property (nonatomic, copy, nullable) void (^fw_stopBlock)(CAAnimation *animation, BOOL finished) NS_REFINED_FOR_SWIFT;
    
    @end

CALayer+FWQuartzCore

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface CALayer (FWQuartzCore)
    
    /// 设置主题背景色,启用主题订阅后可跟随系统改变,清空时需置为nil
    @property (nullable, nonatomic, strong) UIColor *fw_themeBackgroundColor NS_REFINED_FOR_SWIFT;
    
    /// 设置主题边框色,启用主题订阅后可跟随系统改变,清空时需置为nil
    @property (nullable, nonatomic, strong) UIColor *fw_themeBorderColor NS_REFINED_FOR_SWIFT;
    
    /// 设置主题阴影色,启用主题订阅后可跟随系统改变,清空时需置为nil
    @property (nullable, nonatomic, strong) UIColor *fw_themeShadowColor NS_REFINED_FOR_SWIFT;
    
    /// 设置主题内容图片,启用主题订阅后可跟随系统改变,清空时需置为nil
    @property (nullable, nonatomic, strong) UIImage *fw_themeContents NS_REFINED_FOR_SWIFT;
    
    @end

CAGradientLayer+FWQuartzCore

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface CAGradientLayer (FWQuartzCore)
    
    /// 设置主题渐变色,启用主题订阅后可跟随系统改变,清空时需置为nil
    @property (nullable, nonatomic, copy) NSArray<UIColor *> *fw_themeColors NS_REFINED_FOR_SWIFT;
    
    @end

NSObject+FWSwizzle

  • 框架NSObject类包装器

    实现block必须返回一个block,返回的block将被当成originalSelector的新实现,所以要在内部自己处理对super的调用,以及对当前调用方法的self的class的保护判断(因为如果originalClass的originalSelector是继承自父类的,originalClass内部并没有重写这个方法,则我们这个函数最终重写的其实是父类的originalSelector,所以会产生预期之外的class的影响,例如originalClass传进来UIButton.class,则最终可能会影响到UIView.class)。block的参数里第一个为你要修改的class,也即等同于originalClass,第二个参数为你要修改的selector,也即等同于originalSelector,第三个参数是一个block,用于获取originalSelector原本的实现,由于IMP可以直接当成C函数调用,所以可利用它来实现“调用 super”的效果,但由于originalSelector的参数个数、参数类型、返回值类型,都会影响IMP的调用写法,所以这个调用只能由业务自己写

    See more

    Declaration

    Objective-C

    @interface NSObject (FWSwizzle)

UIColor+FWTheme

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIColor (FWTheme)
    
    /// 动态创建主题色,分别指定浅色和深色
    + (UIColor *)fw_themeLight:(UIColor *)light dark:(UIColor *)dark NS_REFINED_FOR_SWIFT;
    
    /// 动态创建主题色,指定提供句柄
    + (UIColor *)fw_themeColor:(UIColor * (^)(FWThemeStyle style))provider NS_REFINED_FOR_SWIFT;
    
    /// 动态创建主题色,指定名称,兼容iOS11+系统方式(仅iOS13+支持动态颜色)和手工指定。失败时返回clear防止崩溃
    + (UIColor *)fw_themeNamed:(NSString *)name NS_REFINED_FOR_SWIFT;
    
    /// 动态创建主题色,指定名称和bundle,兼容iOS11+系统方式(仅iOS13+支持动态颜色)和手工指定。失败时返回clear防止崩溃
    + (UIColor *)fw_themeNamed:(NSString *)name bundle:(nullable NSBundle *)bundle NS_REFINED_FOR_SWIFT;
    
    /// 手工单个注册主题色,未配置主题色或者需兼容iOS11以下时可使用本方式
    + (void)fw_setThemeColor:(nullable UIColor *)color forName:(NSString *)name NS_REFINED_FOR_SWIFT;
    
    /// 手工批量注册主题色,未配置主题色或者需兼容iOS11以下时可使用本方式
    + (void)fw_setThemeColors:(NSDictionary<NSString *, UIColor *> *)nameColors NS_REFINED_FOR_SWIFT;
    
    /// 获取当前主题样式对应静态颜色,主要用于iOS13以下兼容主题切换
    @property (nonatomic, readonly) UIColor *fw_color NS_SWIFT_NAME(__fw_color) NS_REFINED_FOR_SWIFT;
    
    /// 指定主题样式获取对应静态颜色,iOS13+可跟随系统改变
    - (UIColor *)fw_colorForStyle:(FWThemeStyle)style NS_REFINED_FOR_SWIFT;
    
    /// 是否是主题颜色,仅支持判断使用fwTheme创建的颜色
    @property (nonatomic, assign, readonly) BOOL fw_isThemeColor NS_REFINED_FOR_SWIFT;
    
    @end

UIImage+FWTheme

  • UIImage主题分类

    Note

    注意UIImage默认只有name方式且配置了any和dark才支持动态切换,否则只能重新赋值才会变化。 为避免内存泄漏,通过fwTheme方式创建的主题图片不能直接用于显示,显示时请调用fwImage方法
    See more

    Declaration

    Objective-C

    @interface UIImage (FWTheme)

UIImageAsset+FWTheme

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIImageAsset (FWTheme)
    
    /// 创建主题动态图片资源,分别指定浅色和深色,系统方式,推荐使用
    + (UIImageAsset *)fw_themeLight:(nullable UIImage *)light dark:(nullable UIImage *)dark NS_REFINED_FOR_SWIFT;
    
    /// 创建主题动态图片资源,指定提供句柄,内部使用FWThemeObject实现
    + (UIImageAsset *)fw_themeAsset:(UIImage * _Nullable (^)(FWThemeStyle style))provider NS_REFINED_FOR_SWIFT;
    
    /// 获取当前主题样式对应静态图片用于显示,iOS13+可跟随系统改变
    @property (nullable, nonatomic, readonly) UIImage *fw_image NS_REFINED_FOR_SWIFT;
    
    /// 指定主题样式获取对应静态图片用于显示,iOS13+可跟随系统改变
    - (nullable UIImage *)fw_imageForStyle:(FWThemeStyle)style NS_REFINED_FOR_SWIFT;
    
    /// 是否是主题图片资源,仅支持判断使用fwTheme创建的图片资源
    @property (nonatomic, assign, readonly) BOOL fw_isThemeAsset NS_REFINED_FOR_SWIFT;
    
    @end

NSObject+FWTheme

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSObject (FWTheme) <FWThemeObserver>
    
    /// 订阅主题通知并指定主题上下文(如vc|view),非UITraitEnvironment等需指定后才能响应系统主题
    @property (nullable, nonatomic, weak) id<UITraitEnvironment> fw_themeContext NS_REFINED_FOR_SWIFT;
    
    /// 添加iOS13主题改变通知回调,返回订阅唯一标志,需订阅后才生效
    - (nullable NSString *)fw_addThemeListener:(void (^)(FWThemeStyle style))listener NS_REFINED_FOR_SWIFT;
    
    /// iOS13根据订阅唯一标志移除主题通知回调
    - (void)fw_removeThemeListener:(nullable NSString *)identifier NS_REFINED_FOR_SWIFT;
    
    /// iOS13移除所有主题通知回调,一般用于cell重用
    - (void)fw_removeAllThemeListeners NS_REFINED_FOR_SWIFT;
    
    /// iOS13主题改变包装器钩子,如果父类有重写,记得调用super,需订阅后才生效
    - (void)fw_themeChanged:(FWThemeStyle)style NS_REFINED_FOR_SWIFT;
    
    @end
  • iOS13主题订阅UIImageView分类

    See more

    Declaration

    Objective-C

    @interface UIImageView (FWTheme)

UIColor+FWToolkit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIColor (FWToolkit)
    
    /// 获取当前颜色指定透明度的新颜色
    - (UIColor *)fw_colorWithAlpha:(CGFloat)alpha NS_REFINED_FOR_SWIFT;
    
    /// 读取颜色的十六进制值RGB,不含透明度
    @property (nonatomic, assign, readonly) long fw_hexValue NS_REFINED_FOR_SWIFT;
    
    /// 读取颜色的透明度值,范围0~1
    @property (nonatomic, assign, readonly) CGFloat fw_alphaValue NS_REFINED_FOR_SWIFT;
    
    /// 读取颜色的十六进制字符串RGB,不含透明度
    @property (nonatomic, copy, readonly) NSString *fw_hexString NS_REFINED_FOR_SWIFT;
    
    /// 读取颜色的十六进制字符串RGBA|ARGB(透明度为1时RGB),包含透明度
    @property (nonatomic, copy, readonly) NSString *fw_hexAlphaString NS_REFINED_FOR_SWIFT;
    
    /// 设置十六进制颜色标准为ARGB|RGBA,启用为ARGB,默认为RGBA
    @property (class, nonatomic, assign) BOOL fw_colorStandardARGB NS_REFINED_FOR_SWIFT;
    
    /// 获取透明度为1.0的RGB随机颜色
    @property (class, nonatomic, readonly) UIColor *fw_randomColor NS_REFINED_FOR_SWIFT;
    
    /// 从十六进制值初始化,格式:0x20B2AA,透明度为1.0
    + (UIColor *)fw_colorWithHex:(long)hex NS_REFINED_FOR_SWIFT;
    
    /// 从十六进制值初始化,格式:0x20B2AA,自定义透明度
    + (UIColor *)fw_colorWithHex:(long)hex alpha:(CGFloat)alpha NS_REFINED_FOR_SWIFT;
    
    /// 从十六进制字符串初始化,支持RGB、RGBA|ARGB,格式:@"20B2AA", @"#FFFFFF",透明度为1.0,失败时返回clear
    + (UIColor *)fw_colorWithHexString:(NSString *)hexString NS_REFINED_FOR_SWIFT;
    
    /// 从十六进制字符串初始化,支持RGB、RGBA|ARGB,格式:@"20B2AA", @"#FFFFFF",自定义透明度,失败时返回clear
    + (UIColor *)fw_colorWithHexString:(NSString *)hexString alpha:(CGFloat)alpha NS_REFINED_FOR_SWIFT;
    
    @end

UIFont+FWToolkit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIFont (FWToolkit)
    
    /// 全局自定义字体句柄,优先调用
    @property (class, nonatomic, copy, nullable) UIFont * (^fw_fontBlock)(CGFloat size, UIFontWeight weight) NS_REFINED_FOR_SWIFT;
    
    /// 是否自动等比例缩放字体,默认NO。启用后所有fw字体size都会自动*relativeScale
    @property (class, nonatomic, assign) BOOL fw_autoScale NS_REFINED_FOR_SWIFT;
    
    /// 返回系统Thin字体
    + (UIFont *)fw_thinFontOfSize:(CGFloat)size NS_REFINED_FOR_SWIFT;
    /// 返回系统Light字体
    + (UIFont *)fw_lightFontOfSize:(CGFloat)size NS_REFINED_FOR_SWIFT;
    /// 返回系统Regular字体
    + (UIFont *)fw_fontOfSize:(CGFloat)size NS_REFINED_FOR_SWIFT;
    /// 返回系统Medium字体
    + (UIFont *)fw_mediumFontOfSize:(CGFloat)size NS_REFINED_FOR_SWIFT;
    /// 返回系统Semibold字体
    + (UIFont *)fw_semiboldFontOfSize:(CGFloat)size NS_REFINED_FOR_SWIFT;
    /// 返回系统Bold字体
    + (UIFont *)fw_boldFontOfSize:(CGFloat)size NS_REFINED_FOR_SWIFT;
    
    /// 创建指定尺寸和weight的系统字体
    + (UIFont *)fw_fontOfSize:(CGFloat)size weight:(UIFontWeight)weight NS_REFINED_FOR_SWIFT;
    
    @end

UIImage+FWToolkit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIImage (FWToolkit)
    
    /// 从当前图片创建指定透明度的图片
    - (nullable UIImage *)fw_imageWithAlpha:(CGFloat)alpha NS_REFINED_FOR_SWIFT;
    
    /// 从当前图片混合颜色创建UIImage,默认kCGBlendModeDestinationIn模式,适合透明图标
    - (nullable UIImage *)fw_imageWithTintColor:(UIColor *)tintColor NS_REFINED_FOR_SWIFT;
    
    /// 从当前UIImage混合颜色创建UIImage,自定义模式
    - (nullable UIImage *)fw_imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode NS_REFINED_FOR_SWIFT;
    
    /// 缩放图片到指定大小
    - (nullable UIImage *)fw_imageWithScaleSize:(CGSize)size NS_REFINED_FOR_SWIFT;
    
    /// 缩放图片到指定大小,指定模式
    - (nullable UIImage *)fw_imageWithScaleSize:(CGSize)size contentMode:(UIViewContentMode)contentMode NS_REFINED_FOR_SWIFT;
    
    /// 按指定模式绘制图片
    - (void)fw_drawInRect:(CGRect)rect withContentMode:(UIViewContentMode)contentMode clipsToBounds:(BOOL)clipsToBounds NS_REFINED_FOR_SWIFT;
    
    /// 裁剪指定区域图片
    - (nullable UIImage *)fw_imageWithCropRect:(CGRect)rect NS_REFINED_FOR_SWIFT;
    
    /// 指定颜色填充图片边缘
    - (nullable UIImage *)fw_imageWithInsets:(UIEdgeInsets)insets color:(nullable UIColor *)color NS_REFINED_FOR_SWIFT;
    
    /// 拉伸图片(平铺模式),指定端盖区域(不拉伸区域)
    - (UIImage *)fw_imageWithCapInsets:(UIEdgeInsets)insets NS_REFINED_FOR_SWIFT;
    
    /// 拉伸图片(指定模式),指定端盖区域(不拉伸区域)。Tile为平铺模式,Stretch为拉伸模式
    - (UIImage *)fw_imageWithCapInsets:(UIEdgeInsets)insets resizingMode:(UIImageResizingMode)resizingMode NS_REFINED_FOR_SWIFT;
    
    /// 生成圆角图片
    - (nullable UIImage *)fw_imageWithCornerRadius:(CGFloat)radius NS_REFINED_FOR_SWIFT;
    
    /// 按角度常数(0~360)转动图片,默认图片尺寸适应内容
    - (nullable UIImage *)fw_imageWithRotateDegree:(CGFloat)degree NS_REFINED_FOR_SWIFT;
    
    /// 按角度常数(0~360)转动图片,指定图片尺寸是否延伸来适应内容,否则图片尺寸不变,内容被裁剪
    - (nullable UIImage *)fw_imageWithRotateDegree:(CGFloat)degree fitSize:(BOOL)fitSize NS_REFINED_FOR_SWIFT;
    
    /// 生成mark图片
    - (nullable UIImage *)fw_imageWithMaskImage:(UIImage *)maskImage NS_REFINED_FOR_SWIFT;
    
    /// 图片合并,并制定叠加图片的起始位置
    - (nullable UIImage *)fw_imageWithMergeImage:(UIImage *)image atPoint:(CGPoint)point NS_REFINED_FOR_SWIFT;
    
    /// 图片应用CIFilter滤镜处理
    - (nullable UIImage *)fw_imageWithFilter:(CIFilter *)filter NS_REFINED_FOR_SWIFT;
    
    /// 压缩图片到指定字节,图片太大时会改为JPG格式。不保证图片大小一定小于该大小
    - (nullable UIImage *)fw_compressImageWithMaxLength:(NSInteger)maxLength NS_REFINED_FOR_SWIFT;
    
    /// 压缩图片到指定字节,图片太大时会改为JPG格式,可设置递减压缩率,默认0.1。不保证图片大小一定小于该大小
    - (nullable NSData *)fw_compressDataWithMaxLength:(NSInteger)maxLength compressRatio:(CGFloat)compressRatio NS_REFINED_FOR_SWIFT;
    
    /// 长边压缩图片尺寸,获取等比例的图片
    - (nullable UIImage *)fw_compressImageWithMaxWidth:(NSInteger)maxWidth NS_REFINED_FOR_SWIFT;
    
    /// 通过指定图片最长边,获取等比例的图片size
    - (CGSize)fw_scaleSizeWithMaxWidth:(CGFloat)maxWidth NS_REFINED_FOR_SWIFT;
    
    /// 获取原始渲染模式图片,始终显示原色,不显示tintColor。默认自动根据上下文
    @property (nonatomic, readonly) UIImage *fw_originalImage NS_REFINED_FOR_SWIFT;
    
    /// 获取模板渲染模式图片,始终显示tintColor,不显示原色。默认自动根据上下文
    @property (nonatomic, readonly) UIImage *fw_templateImage NS_REFINED_FOR_SWIFT;
    
    /// 判断图片是否有透明通道
    @property (nonatomic, assign, readonly) BOOL fw_hasAlpha NS_REFINED_FOR_SWIFT;
    
    /// 获取当前图片的像素大小,多倍图会放大到一倍
    @property (nonatomic, assign, readonly) CGSize fw_pixelSize NS_REFINED_FOR_SWIFT;
    
    /// 从视图创建UIImage,生成截图,主线程调用
    + (nullable UIImage *)fw_imageWithView:(UIView *)view NS_REFINED_FOR_SWIFT;
    
    /// 从颜色创建UIImage,默认尺寸1x1
    + (nullable UIImage *)fw_imageWithColor:(UIColor *)color NS_REFINED_FOR_SWIFT;
    
    /// 从颜色创建UIImage,指定尺寸
    + (nullable UIImage *)fw_imageWithColor:(UIColor *)color size:(CGSize)size NS_REFINED_FOR_SWIFT;
    
    /// 从颜色创建UIImage,指定尺寸和圆角
    + (nullable UIImage *)fw_imageWithColor:(UIColor *)color size:(CGSize)size cornerRadius:(CGFloat)radius NS_REFINED_FOR_SWIFT;
    
    /// 从block创建UIImage,指定尺寸
    + (nullable UIImage *)fw_imageWithSize:(CGSize)size block:(void (NS_NOESCAPE ^)(CGContextRef context))block NS_REFINED_FOR_SWIFT;
    
    /// 保存图片到相册,保存成功时error为nil
    - (void)fw_saveImageWithCompletion:(nullable void (^)(NSError * _Nullable error))completion NS_SWIFT_NAME(__fw_saveImage(completion:)) NS_REFINED_FOR_SWIFT;
    
    // 保存视频到相册,保存成功时error为nil。如果视频地址为NSURL,需使用NSURL.path
    + (void)fw_saveVideo:(NSString *)videoPath withCompletion:(nullable void (^)(NSError * _Nullable error))completion NS_REFINED_FOR_SWIFT;
    
    @end

UINavigationController+FWToolkit

  • 当自定义left按钮或隐藏导航栏之后,系统返回手势默认失效,可调用此方法全局开启返回代理。开启后自动将开关代理给顶部VC的shouldPopController、popGestureEnabled属性控制。interactivePop手势禁用时不生效

    See more

    Declaration

    Objective-C

    @interface UINavigationController (FWToolkit)

UIDevice+FWUIKit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIDevice (FWUIKit)
    
    /// 设置设备token原始Data,格式化并保存
    + (void)fw_setDeviceTokenData:(nullable NSData *)tokenData NS_REFINED_FOR_SWIFT;
    
    /// 获取或设置设备Token格式化后的字符串
    @property (class, nonatomic, copy, nullable) NSString *fw_deviceToken NS_REFINED_FOR_SWIFT;
    
    /// 获取设备模型,格式:"iPhone6,1"
    @property (class, nonatomic, copy, readonly, nullable) NSString *fw_deviceModel NS_REFINED_FOR_SWIFT;
    
    /// 获取设备IDFV(内部使用),同账号应用全删除后会改变,可通过keychain持久化
    @property (class, nonatomic, copy, readonly, nullable) NSString *fw_deviceIDFV NS_REFINED_FOR_SWIFT;
    
    /// 获取设备IDFA(外部使用),重置广告或系统后会改变,需先检测广告追踪权限,启用Tracking子模块后生效
    @property (class, nonatomic, copy, readonly, nullable) NSString *fw_deviceIDFA NS_REFINED_FOR_SWIFT;
    
    @end

UIButton+FWUIKit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIButton (FWUIKit)
    
    /// 自定义按钮禁用时的alpha,如0.5,默认0不生效
    @property (nonatomic, assign) CGFloat fw_disabledAlpha NS_REFINED_FOR_SWIFT;
    
    /// 自定义按钮高亮时的alpha,如0.5,默认0不生效
    @property (nonatomic, assign) CGFloat fw_highlightedAlpha NS_REFINED_FOR_SWIFT;
    
    /// 快速设置文本按钮
    - (void)fw_setTitle:(nullable NSString *)title font:(nullable UIFont *)font titleColor:(nullable UIColor *)titleColor NS_REFINED_FOR_SWIFT;
    
    /// 快速设置文本
    - (void)fw_setTitle:(nullable NSString *)title NS_REFINED_FOR_SWIFT;
    
    /// 快速设置图片
    - (void)fw_setImage:(nullable UIImage *)image NS_REFINED_FOR_SWIFT;
    
    /// 设置图片的居中边位置,需要在setImage和setTitle之后调用才生效,且button大小大于图片+文字+间距
    ///
    /// imageEdgeInsets: 仅有image时相对于button,都有时上左下相对于button,右相对于title
    /// titleEdgeInsets: 仅有title时相对于button,都有时上右下相对于button,左相对于image
    - (void)fw_setImageEdge:(UIRectEdge)edge spacing:(CGFloat)spacing NS_REFINED_FOR_SWIFT;
    
    /// 设置状态背景色
    - (void)fw_setBackgroundColor:(nullable UIColor *)backgroundColor forState:(UIControlState)state NS_REFINED_FOR_SWIFT;
    
    /// 快速创建文本按钮
    + (instancetype)fw_buttonWithTitle:(nullable NSString *)title font:(nullable UIFont *)font titleColor:(nullable UIColor *)titleColor NS_REFINED_FOR_SWIFT;
    
    /// 快速创建图片按钮
    + (instancetype)fw_buttonWithImage:(nullable UIImage *)image NS_REFINED_FOR_SWIFT;
    
    @end

UIScrollView+FWUIKit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIScrollView (FWUIKit)
    
    /// 判断当前scrollView内容是否足够滚动
    @property (nonatomic, assign, readonly) BOOL fw_canScroll NS_REFINED_FOR_SWIFT;
    
    /// 判断当前的scrollView内容是否足够水平滚动
    @property (nonatomic, assign, readonly) BOOL fw_canScrollHorizontal NS_REFINED_FOR_SWIFT;
    
    /// 判断当前的scrollView内容是否足够纵向滚动
    @property (nonatomic, assign, readonly) BOOL fw_canScrollVertical NS_REFINED_FOR_SWIFT;
    
    /// 当前scrollView滚动到指定边
    - (void)fw_scrollToEdge:(UIRectEdge)edge animated:(BOOL)animated NS_REFINED_FOR_SWIFT;
    
    /// 是否已滚动到指定边
    - (BOOL)fw_isScrollToEdge:(UIRectEdge)edge NS_REFINED_FOR_SWIFT;
    
    /// 获取当前的scrollView滚动到指定边时的contentOffset(包含contentInset)
    - (CGPoint)fw_contentOffsetOfEdge:(UIRectEdge)edge NS_REFINED_FOR_SWIFT;
    
    /// 总页数,自动识别翻页方向
    @property (nonatomic, assign, readonly) NSInteger fw_totalPage NS_REFINED_FOR_SWIFT;
    
    /// 当前页数,不支持动画,自动识别翻页方向
    @property (nonatomic, assign) NSInteger fw_currentPage NS_REFINED_FOR_SWIFT;
    
    /// 设置当前页数,支持动画,自动识别翻页方向
    - (void)fw_setCurrentPage:(NSInteger)page animated:(BOOL)animated NS_REFINED_FOR_SWIFT;
    
    /// 是否是最后一页,自动识别翻页方向
    @property (nonatomic, assign, readonly) BOOL fw_isLastPage NS_REFINED_FOR_SWIFT;
    
    @end

UIPageControl+FWUIKit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIPageControl (FWUIKit)
    
    /// 自定义圆点大小,默认{10, 10}
    @property (nonatomic, assign) CGSize fw_preferredSize NS_REFINED_FOR_SWIFT;
    
    @end

UISlider+FWUIKit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UISlider (FWUIKit)
    
    /// 中间圆球的大小,默认zero
    @property (nonatomic, assign) CGSize fw_thumbSize NS_REFINED_FOR_SWIFT;
    
    /// 中间圆球的颜色,默认nil
    @property (nonatomic, strong, nullable) UIColor *fw_thumbColor NS_REFINED_FOR_SWIFT;
    
    @end

UISwitch+FWUIKit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UISwitch (FWUIKit)
    
    /// 自定义尺寸大小,默认{51,31}
    @property (nonatomic, assign) CGSize fw_preferredSize NS_REFINED_FOR_SWIFT;
    
    @end

UITextField+FWUIKit

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UITextField (FWUIKit)
    
    /// 最大字数限制,0为无限制,二选一
    @property (nonatomic, assign) NSInteger fw_maxLength NS_REFINED_FOR_SWIFT;
    
    /// 最大Unicode字数限制(中文为1,英文为0.5),0为无限制,二选一
    @property (nonatomic, assign) NSInteger fw_maxUnicodeLength NS_REFINED_FOR_SWIFT;
    
    /// 自定义文字改变处理句柄,默认nil
    @property (nonatomic, copy, nullable) void (^fw_textChangedBlock)(NSString *text) NS_REFINED_FOR_SWIFT;
    
    /// 文本长度发生改变,自动检测字数限制,用于代码设置text等场景
    - (void)fw_textLengthChanged NS_REFINED_FOR_SWIFT;
    
    /// 获取满足最大字数限制的过滤后的文本,无需再调用textLengthChanged
    - (NSString *)fw_filterText:(NSString *)text NS_REFINED_FOR_SWIFT;
    
    /// 设置自动完成时间间隔,默认0.5秒,和autoCompleteBlock配套使用
    @property (nonatomic, assign) NSTimeInterval fw_autoCompleteInterval NS_REFINED_FOR_SWIFT;
    
    /// 设置自动完成处理句柄,默认nil,注意输入框内容为空时会立即触发
    @property (nullable, nonatomic, copy) void (^fw_autoCompleteBlock)(NSString *text) NS_REFINED_FOR_SWIFT;
    
    @end

UIAlertAction+FWAlert

  • 系统弹出框动作分类,自定义属性

    Note

    系统弹出动作title仅支持NSString,如果需要支持NSAttributedString等,请使用FWAlertController
    See more

    Declaration

    Objective-C

    @interface UIAlertAction (FWAlert)

UIAlertController+FWAlert

  • 系统弹出框控制器分类,自定义样式

    Note

    系统弹出框title和message仅支持NSString,如果需要支持NSAttributedString等,请使用FWAlertController
    See more

    Declaration

    Objective-C

    @interface UIAlertController (FWAlert)

UIImage+FWAnimated

NSData+FWAnimated

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSData (FWAnimated)
    
    /// 获取图片数据的格式,未知格式返回FWImageFormatUndefined
    + (FWImageFormat)fw_imageFormatForImageData:(nullable NSData *)data NS_REFINED_FOR_SWIFT;
    
    /// 图片格式转化为UTType,未知格式返回kUTTypeImage
    + (nonnull CFStringRef)fw_UTTypeFromImageFormat:(FWImageFormat)format CF_RETURNS_NOT_RETAINED NS_REFINED_FOR_SWIFT;
    
    /// UTType转化为图片格式,未知格式返回FWImageFormatUndefined
    + (FWImageFormat)fw_imageFormatFromUTType:(nonnull CFStringRef)uttype NS_REFINED_FOR_SWIFT;
    
    /// 图片格式转化为mimeType,未知格式返回application/octet-stream
    + (NSString *)fw_mimeTypeFromImageFormat:(FWImageFormat)format NS_REFINED_FOR_SWIFT;
    
    /// 文件后缀转化为mimeType,未知后缀返回application/octet-stream
    + (NSString *)fw_mimeTypeFromExtension:(NSString *)extension NS_REFINED_FOR_SWIFT;
    
    /// 图片数据编码为base64字符串,可直接用于H5显示等,字符串格式:data:image/png;base64,数据
    + (nullable NSString *)fw_base64StringForImageData:(nullable NSData *)data NS_REFINED_FOR_SWIFT;
    
    @end

FWAssetManager

NSMutableAttributedString+FWAttributedLabel

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSMutableAttributedString (FWAttributedLabel)
    
    @property (nonatomic, strong, nullable) UIColor *fw_textColor NS_REFINED_FOR_SWIFT;
    - (void)fw_setTextColor:(UIColor*)color range:(NSRange)range NS_REFINED_FOR_SWIFT;
    
    @property (nonatomic, strong, nullable) UIFont *fw_font NS_REFINED_FOR_SWIFT;
    - (void)fw_setFont:(UIFont*)font range:(NSRange)range NS_REFINED_FOR_SWIFT;
    
    - (void)fw_setUnderlineStyle:(CTUnderlineStyle)style
                       modifier:(CTUnderlineStyleModifiers)modifier NS_REFINED_FOR_SWIFT;
    - (void)fw_setUnderlineStyle:(CTUnderlineStyle)style
                       modifier:(CTUnderlineStyleModifiers)modifier
                          range:(NSRange)range NS_REFINED_FOR_SWIFT;
    
    @end

UIBarItem+FWBadge

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIBarItem (FWBadge)
    
    /// 获取UIBarItem(UIBarButtonItem、UITabBarItem)内部的view,通常对于navigationItem和tabBarItem而言,需要在设置为item后并且在bar可见时(例如 viewDidAppear:及之后)获取fwView才有值
    @property (nullable, nonatomic, weak, readonly) UIView *fw_view NS_REFINED_FOR_SWIFT;
    
    /// 当item内的view生成后就会调用一次这个block,仅对UIBarButtonItem、UITabBarItem有效
    @property (nullable, nonatomic, copy) void (^fw_viewLoadedBlock)(__kindof UIBarItem *item, UIView *view) NS_REFINED_FOR_SWIFT;
    
    @end

UIBarButtonItem+FWBadge

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIBarButtonItem (FWBadge)
    
    /// 显示右上角提醒灯,上右偏移指定距离
    - (void)fw_showBadgeView:(FWBadgeView *)badgeView badgeValue:(nullable NSString *)badgeValue NS_REFINED_FOR_SWIFT;
    
    /// 隐藏提醒灯
    - (void)fw_hideBadgeView NS_REFINED_FOR_SWIFT;
    
    @end

UITabBarItem+FWBadge

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UITabBarItem (FWBadge)
    
    /// 获取一个UITabBarItem内显示图标的UIImageView,如果找不到则返回nil
    @property (nullable, nonatomic, weak, readonly) UIImageView *fw_imageView NS_REFINED_FOR_SWIFT;
    
    /// 显示右上角提醒灯,上右偏移指定距离
    - (void)fw_showBadgeView:(FWBadgeView *)badgeView badgeValue:(nullable NSString *)badgeValue NS_REFINED_FOR_SWIFT;
    
    /// 隐藏提醒灯
    - (void)fw_hideBadgeView NS_REFINED_FOR_SWIFT;
    
    @end

FWBarrageTrackInfo

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface CALayer (FWBarrage)
    
    - (nullable UIImage *)fw_convertContentToImageWithSize:(CGSize)contentSize NS_REFINED_FOR_SWIFT;
    
    @end

FWCollectionViewSectionConfig

UIScrollView+FWEmptyPlugin

UIScrollView+FWScrollOverlayView

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIScrollView (FWScrollOverlayView)
    
    /// 滚动视图自定义浮层,用于显示空界面等,兼容UITableView|UICollectionView
    @property (nonatomic, strong, readonly) UIView *fw_overlayView NS_REFINED_FOR_SWIFT;
    
    /// 是否显示自定义浮层
    @property (nonatomic, assign, readonly) BOOL fw_hasOverlayView NS_REFINED_FOR_SWIFT;
    
    /// 显示自定义浮层,自动添加到滚动视图顶部、表格视图底部
    - (void)fw_showOverlayView NS_REFINED_FOR_SWIFT;
    
    /// 显示自定义浮层,执行渐变动画,自动添加到滚动视图顶部、表格视图底部
    - (void)fw_showOverlayViewAnimated:(BOOL)animated NS_REFINED_FOR_SWIFT;
    
    /// 隐藏自定义浮层,自动从滚动视图移除
    - (void)fw_hideOverlayView NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIImage (FWCropRotate)
    
    - (nonnull UIImage *)fw_croppedImageWithFrame:(CGRect)frame angle:(NSInteger)angle circularClip:(BOOL)circular NS_REFINED_FOR_SWIFT;
    
    @end

UIImagePickerController+FWImagePickerPluginImpl

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIImagePickerController (FWImagePickerPluginImpl)
    
    /**
     快速创建单选照片选择器(仅图片),自动设置delegate
     
     @param sourceType 选择器类型
     @param allowsEditing 是否允许编辑
     @param completion 完成回调。参数1为图片,2为信息字典,3为是否取消
     @return 照片选择器,不支持的返回nil
     */
    + (nullable UIImagePickerController *)fw_pickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType
                                                allowsEditing:(BOOL)allowsEditing
                                                   completion:(void (^)(UIImage * _Nullable image, NSDictionary * _Nullable info, BOOL cancel))completion NS_REFINED_FOR_SWIFT;
    
    /**
     快速创建单选照片选择器,可自定义dismiss流程,自动设置delegate
     
     @param sourceType 选择器类型
     @param filterType 过滤类型,默认0同系统
     @param allowsEditing 是否允许编辑
     @param shouldDismiss 是否先关闭照片选择器再回调,如果先关闭则回调参数1为nil
     @param completion 完成回调。参数1为照片选择器,2为对象(UIImage|PHLivePhoto|NSURL),3为信息字典,4为是否取消
     @return 照片选择器,不支持的返回nil
     */
    + (nullable UIImagePickerController *)fw_pickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType
                                                   filterType:(FWImagePickerFilterType)filterType
                                                allowsEditing:(BOOL)allowsEditing
                                                shouldDismiss:(BOOL)shouldDismiss
                                                   completion:(void (^)(UIImagePickerController * _Nullable picker, id _Nullable object, NSDictionary * _Nullable info, BOOL cancel))completion NS_REFINED_FOR_SWIFT;
    
    /**
     快速创建单选照片选择器,使用自定义裁剪控制器编辑
     
     @param sourceType 选择器类型
     @param cropController 自定义裁剪控制器句柄,nil时自动创建默认裁剪控制器
     @param completion 完成回调。参数1为图片,2为信息字典,3为是否取消
     @return 照片选择器,不支持的返回nil
     */
    + (nullable UIImagePickerController *)fw_pickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType
                                               cropController:(nullable FWImageCropController * (^)(UIImage *image))cropController
                                                   completion:(void (^)(UIImage * _Nullable image, NSDictionary * _Nullable info, BOOL cancel))completion NS_REFINED_FOR_SWIFT;
    
    @end

PHPickerViewController+FWImagePickerPluginImpl

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface PHPickerViewController (FWImagePickerPluginImpl)
    
    /**
     快速创建多选照片选择器(仅图片),自动设置delegate
     
     @param selectionLimit 最大选择数量
     @param completion 完成回调,主线程。参数1为图片数组,2为结果数组,3为是否取消
     @return 照片选择器
     */
    + (PHPickerViewController *)fw_pickerControllerWithSelectionLimit:(NSInteger)selectionLimit
                                              completion:(void (^)(NSArray<UIImage *> *images, NSArray<PHPickerResult *> *results, BOOL cancel))completion NS_REFINED_FOR_SWIFT;
    
    /**
     快速创建多选照片选择器,可自定义dismiss流程,自动设置delegate
     @note 当选择视频时,completion回调对象为NSURL临时文件路径,使用完毕后可手工删除或等待系统自动删除
     
     @param filterType 过滤类型,默认0同系统
     @param selectionLimit 最大选择数量
     @param shouldDismiss 是否先关闭照片选择器再回调,如果先关闭则回调参数1为nil
     @param completion 完成回调,主线程。参数1为照片选择器,2为对象数组(UIImage|PHLivePhoto|NSURL),3为结果数组,4为是否取消
     @return 照片选择器
     */
    + (PHPickerViewController *)fw_pickerControllerWithFilterType:(FWImagePickerFilterType)filterType
                                      selectionLimit:(NSInteger)selectionLimit
                                       shouldDismiss:(BOOL)shouldDismiss
                                          completion:(void (^)(PHPickerViewController * _Nullable picker, NSArray *objects, NSArray<PHPickerResult *> *results, BOOL cancel))completion NS_REFINED_FOR_SWIFT;
    
    /**
     快速创建单选照片选择器(仅图片),使用自定义裁剪控制器编辑
     
     @param cropController 自定义裁剪控制器句柄,nil时自动创建默认裁剪控制器
     @param completion 完成回调,主线程。参数1为图片,2为结果信息,3为是否取消
     @return 照片选择器
     */
    + (PHPickerViewController *)fw_pickerControllerWithCropController:(nullable FWImageCropController * (^)(UIImage *image))cropController
                                              completion:(void (^)(UIImage * _Nullable image, PHPickerResult * _Nullable result, BOOL cancel))completion NS_REFINED_FOR_SWIFT;
    
    @end

PHPhotoLibrary+FWImagePickerPluginImpl

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface PHPhotoLibrary (FWImagePickerPluginImpl)
    
    /**
     图片选择器选择视频时临时文件存放目录,使用完成后需自行删除
     */
    @property (class, nonatomic, copy, readonly) NSString *fw_pickerControllerVideoCachePath NS_REFINED_FOR_SWIFT;
    
    /**
     快速创建照片选择器(仅图片)
     
     @param selectionLimit 最大选择数量,iOS14以下只支持单选
     @param allowsEditing 是否允许编辑,仅iOS14以下支持编辑
     @param completion 完成回调,主线程。参数1为图片数组,2为结果数组,3为是否取消
     @return 照片选择器
     */
    + (nullable __kindof UIViewController *)fw_pickerControllerWithSelectionLimit:(NSInteger)selectionLimit
                                                                   allowsEditing:(BOOL)allowsEditing
                                                                      completion:(void (^)(NSArray<UIImage *> *images, NSArray *results, BOOL cancel))completion NS_REFINED_FOR_SWIFT;
    
    /**
     快速创建照片选择器,可自定义dismiss流程
     
     @param filterType 过滤类型,默认0同系统
     @param selectionLimit 最大选择数量,iOS14以下只支持单选
     @param allowsEditing 是否允许编辑,仅iOS14以下支持编辑
     @param shouldDismiss 是否先关闭照片选择器再回调,如果先关闭则回调参数1为nil
     @param completion 完成回调,主线程。参数1为照片选择器,2为对象数组(UIImage|PHLivePhoto|NSURL),3位结果数组,4为是否取消
     @return 照片选择器
     */
    + (nullable __kindof UIViewController *)fw_pickerControllerWithFilterType:(FWImagePickerFilterType)filterType
                                                              selectionLimit:(NSInteger)selectionLimit
                                                               allowsEditing:(BOOL)allowsEditing
                                                               shouldDismiss:(BOOL)shouldDismiss
                                                                  completion:(void (^)(__kindof UIViewController * _Nullable picker, NSArray *objects, NSArray *results, BOOL cancel))completion NS_REFINED_FOR_SWIFT;
    
    /**
     快速创建单选照片选择器(仅图片),使用自定义裁剪控制器编辑
     
     @param cropController 自定义裁剪控制器句柄,nil时自动创建默认裁剪控制器
     @param completion 完成回调,主线程。参数1为图片,2为结果信息,3为是否取消
     @return 照片选择器
     */
    + (nullable __kindof UIViewController *)fw_pickerControllerWithCropController:(nullable FWImageCropController * (^)(UIImage *image))cropController
                                                                      completion:(void (^)(UIImage * _Nullable image, id _Nullable result, BOOL cancel))completion NS_REFINED_FOR_SWIFT;
    
    @end

UIImage+FWImagePlugin

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIImage (FWImagePlugin)
    
    /// 根据名称加载UIImage,优先加载图片文件(无缓存),文件不存在时尝试系统imageNamed方式(有缓存)
    + (nullable UIImage *)fw_imageNamed:(NSString *)name NS_REFINED_FOR_SWIFT;
    
    /// 根据名称从指定bundle加载UIImage,优先加载图片文件(无缓存),文件不存在时尝试系统imageNamed方式(有缓存)
    + (nullable UIImage *)fw_imageNamed:(NSString *)name bundle:(nullable NSBundle *)bundle NS_REFINED_FOR_SWIFT;
    
    /// 根据名称从指定bundle加载UIImage,优先加载图片文件(无缓存),文件不存在时尝试系统imageNamed方式(有缓存)。支持设置图片解码选项
    + (nullable UIImage *)fw_imageNamed:(NSString *)name bundle:(nullable NSBundle *)bundle options:(nullable NSDictionary<FWImageCoderOptions, id> *)options NS_REFINED_FOR_SWIFT;
    
    /// 从图片文件路径解码创建UIImage,自动识别scale,支持动图
    + (nullable UIImage *)fw_imageWithContentsOfFile:(NSString *)path NS_REFINED_FOR_SWIFT;
    
    /// 从图片数据解码创建UIImage,scale为1,支持动图
    + (nullable UIImage *)fw_imageWithData:(nullable NSData *)data NS_REFINED_FOR_SWIFT;
    
    /// 从图片数据解码创建UIImage,指定scale,支持动图
    + (nullable UIImage *)fw_imageWithData:(nullable NSData *)data scale:(CGFloat)scale NS_REFINED_FOR_SWIFT;
    
    /// 从图片数据解码创建UIImage,指定scale,支持动图。支持设置图片解码选项
    + (nullable UIImage *)fw_imageWithData:(nullable NSData *)data scale:(CGFloat)scale options:(nullable NSDictionary<FWImageCoderOptions, id> *)options NS_REFINED_FOR_SWIFT;
    
    /// 从UIImage编码创建图片数据,支持动图
    + (nullable NSData *)fw_dataWithImage:(nullable UIImage *)image NS_REFINED_FOR_SWIFT;
    
    /// 从UIImage编码创建图片数据,支持动图。支持设置图片编码选项
    + (nullable NSData *)fw_dataWithImage:(nullable UIImage *)image options:(nullable NSDictionary<FWImageCoderOptions, id> *)options NS_REFINED_FOR_SWIFT;
    
    /// 下载网络图片并返回下载凭据
    + (nullable id)fw_downloadImage:(nullable id)url
                        completion:(void (^)(UIImage * _Nullable image, NSError * _Nullable error))completion
                          progress:(nullable void (^)(double progress))progress NS_REFINED_FOR_SWIFT;
    
    /// 下载网络图片并返回下载凭据,指定option
    + (nullable id)fw_downloadImage:(nullable id)url
                           options:(FWWebImageOptions)options
                           context:(nullable NSDictionary<FWImageCoderOptions, id> *)context
                        completion:(void (^)(UIImage * _Nullable image, NSError * _Nullable error))completion
                          progress:(nullable void (^)(double progress))progress NS_REFINED_FOR_SWIFT;
    
    /// 指定下载凭据取消网络图片下载
    + (void)fw_cancelImageDownload:(nullable id)receipt NS_REFINED_FOR_SWIFT;
    
    @end

UIImageView+FWImagePlugin

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIImageView (FWImagePlugin)
    
    /// 自定义图片插件,未设置时自动从插件池加载
    @property (nonatomic, strong, nullable) id<FWImagePlugin> fw_imagePlugin NS_REFINED_FOR_SWIFT;
    
    /// 当前正在加载的网络图片URL
    @property (nonatomic, copy, readonly, nullable) NSURL *fw_imageURL NS_REFINED_FOR_SWIFT;
    
    /// 加载网络图片,优先加载插件,默认使用框架网络库
    - (void)fw_setImageWithURL:(nullable id)url NS_REFINED_FOR_SWIFT;
    
    /// 加载网络图片,支持占位,优先加载插件,默认使用框架网络库
    - (void)fw_setImageWithURL:(nullable id)url
             placeholderImage:(nullable UIImage *)placeholderImage NS_REFINED_FOR_SWIFT;
    
    /// 加载网络图片,支持占位和回调,优先加载插件,默认使用框架网络库
    - (void)fw_setImageWithURL:(nullable id)url
             placeholderImage:(nullable UIImage *)placeholderImage
                   completion:(nullable void (^)(UIImage * _Nullable image, NSError * _Nullable error))completion NS_REFINED_FOR_SWIFT;
    
    /// 加载网络图片,支持占位、选项、回调和进度,优先加载插件,默认使用框架网络库
    - (void)fw_setImageWithURL:(nullable id)url
             placeholderImage:(nullable UIImage *)placeholderImage
                      options:(FWWebImageOptions)options
                      context:(nullable NSDictionary<FWImageCoderOptions, id> *)context
                   completion:(nullable void (^)(UIImage * _Nullable image, NSError * _Nullable error))completion
                     progress:(nullable void (^)(double progress))progress NS_REFINED_FOR_SWIFT;
    
    /// 取消加载网络图片请求
    - (void)fw_cancelImageRequest NS_REFINED_FOR_SWIFT;
    
    /// 创建动画ImageView视图,优先加载插件,默认UIImageView
    + (UIImageView *)fw_animatedImageView NS_SWIFT_NAME(__fw_animatedImageView()) NS_REFINED_FOR_SWIFT;
    
    @end
  • Model模型解析分类,参考自YYModel

    See more

    Declaration

    Objective-C

    @interface NSObject (FWModel)

UINavigationController+FWBarTransition

UINavigationController+FWFullscreenPopGesture

UINavigationBar+FWStyle

UIScrollView+FWRefreshPlugin

UIScrollView+FWPullRefresh

UIScrollView+FWInfiniteScroll

FWToastPlugin

  • UIWindow全局使用吐司插件,内部使用UIWindow.fw.mainWindow

    See more

    Declaration

    Objective-C

    @interface UIWindow (FWToastPlugin)

UIActivityIndicatorView+FWViewPlugin

UINavigationController+FWTransition

FWWebView

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIProgressView (FWWebView)
    
    /// 设置Web加载进度,0和1自动切换隐藏。可设置trackTintColor为clear,隐藏背景色
    @property (nonatomic, assign) float fw_webProgress NS_REFINED_FOR_SWIFT;
    
    @end

FWWebViewBridge

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface WKWebView (FWWebViewBridge)
    
    /// 设置Javascript桥接器强引用属性,防止使用过程中被释放
    @property (nonatomic, strong, nullable) FWWebViewJsBridge *fw_jsBridge NS_REFINED_FOR_SWIFT;
    
    /// 获取当前UserAgent,未自定义时为默认,示例:Mozilla/5.0 (iPhone; CPU OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148
    @property (nonatomic, copy, readonly) NSString *fw_userAgent NS_REFINED_FOR_SWIFT;
    
    /// 获取默认浏览器UserAgent,包含应用信息,示例:Mozilla/5.0 (iPhone; CPU OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Safari/605.1.15 Example/1.0.0
    @property (class, nonatomic, copy, readonly) NSString *fw_browserUserAgent NS_REFINED_FOR_SWIFT;
    
    /// 获取默认浏览器扩展UserAgent,不含平台信息,可用于applicationNameForUserAgent,示例:Mobile/15E148 Safari/605.1.15 Example/1.0.0
    @property (class, nonatomic, copy, readonly) NSString *fw_extensionUserAgent NS_REFINED_FOR_SWIFT;
    
    /// 获取默认请求UserAgent,可用于网络请求,示例:Example/1.0.0 (iPhone; iOS 14.2; Scale/3.00)
    @property (class, nonatomic, copy, readonly) NSString *fw_requestUserAgent NS_REFINED_FOR_SWIFT;
    
    /// 清空网页缓存,完成后回调。单个网页请求指定URLRequest.cachePolicy即可
    + (void)fw_clearCache:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    @end
  • NSArray分类

    Note

    如果需要数组weak引用元素,使用[NSValue valueWithNonretainedObject:object]即可
    See more

    Declaration

    Objective-C

    @interface NSArray <__covariant ObjectType>(FWApplication)

NSMutableArray+FWApplication

NSAttributedString+FWApplication

  • 注意iOS在后台运行时,如果调用NSAttributedString解析html会导致崩溃(如动态切换深色模式时在后台解析html)。解决方法是提前在前台解析好或者后台异步到下一个主线程RunLoop

    See more

    Declaration

    Objective-C

    @interface NSAttributedString (FWApplication)
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSBundle (FWApplication)
    
    // 自定义GoogleMaps反解析地址结果语言,为nil时不指定
    + (void)fw_setGoogleMapsLanguage:(nullable NSString *)language NS_REFINED_FOR_SWIFT;
    
    // 自定义GooglePlaces查询地址结果语言,为nil时不指定
    + (void)fw_setGooglePlacesLanguage:(nullable NSString *)language NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSData (FWApplication)
    
    #pragma mark - Encrypt
    
    /// 利用AES加密数据
    - (nullable NSData *)fw_AESEncryptWithKey:(NSString *)key andIV:(NSData *)iv NS_REFINED_FOR_SWIFT;
    
    /// 利用AES解密数据
    - (nullable NSData *)fw_AESDecryptWithKey:(NSString *)key andIV:(NSData *)iv NS_REFINED_FOR_SWIFT;
    
    /// 利用3DES加密数据
    - (nullable NSData *)fw_DES3EncryptWithKey:(NSString *)key andIV:(NSData *)iv NS_REFINED_FOR_SWIFT;
    
    /// 利用3DES解密数据
    - (nullable NSData *)fw_DES3DecryptWithKey:(NSString *)key andIV:(NSData *)iv NS_REFINED_FOR_SWIFT;
    
    #pragma mark - RSA
    
    /// RSA公钥加密,数据传输安全,使用默认标签,执行base64编码
    - (nullable NSData *)fw_RSAEncryptWithPublicKey:(NSString *)publicKey NS_REFINED_FOR_SWIFT;
    
    /// RSA公钥加密,数据传输安全,可自定义标签,指定base64编码
    - (nullable NSData *)fw_RSAEncryptWithPublicKey:(NSString *)publicKey andTag:(NSString *)tagName base64Encode:(BOOL)base64Encode NS_REFINED_FOR_SWIFT;
    
    /// RSA私钥解密,数据传输安全,使用默认标签,执行base64解密
    - (nullable NSData *)fw_RSADecryptWithPrivateKey:(NSString *)privateKey NS_REFINED_FOR_SWIFT;
    
    /// RSA私钥解密,数据传输安全,可自定义标签,指定base64解码
    - (nullable NSData *)fw_RSADecryptWithPrivateKey:(NSString *)privateKey andTag:(NSString *)tagName base64Decode:(BOOL)base64Decode NS_REFINED_FOR_SWIFT;
    
    /// RSA私钥加签,防篡改防否认,使用默认标签,执行base64编码
    - (nullable NSData *)fw_RSASignWithPrivateKey:(NSString *)privateKey NS_REFINED_FOR_SWIFT;
    
    /// RSA私钥加签,防篡改防否认,可自定义标签,指定base64编码
    - (nullable NSData *)fw_RSASignWithPrivateKey:(NSString *)privateKey andTag:(NSString *)tagName base64Encode:(BOOL)base64Encode NS_REFINED_FOR_SWIFT;
    
    /// RSA公钥验签,防篡改防否认,使用默认标签,执行base64解密
    - (nullable NSData *)fw_RSAVerifyWithPublicKey:(NSString *)publicKey NS_REFINED_FOR_SWIFT;
    
    /// RSA公钥验签,防篡改防否认,可自定义标签,指定base64解码
    - (nullable NSData *)fw_RSAVerifyWithPublicKey:(NSString *)publicKey andTag:(NSString *)tagName base64Decode:(BOOL)base64Decode NS_REFINED_FOR_SWIFT;
    
    @end
  • NSDate默认GMT时区;NSTimeZone默认系统时区(可设置应用默认时区);NSDateFormatter默认当前时区(可自定义),格式化时自动修正NSDate时区(无需手工修正NSDate);NSLocale默认当前语言环境

    See more

    Declaration

    Objective-C

    @interface NSDate (FWApplication)
  • NSDictionary分类

    See more

    Declaration

    Objective-C

    @interface NSDictionary <__covariant KeyType,
                             __covariant ObjectType>(FWApplication)

Macro

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSFileManager (FWApplication)
    
    #pragma mark - Path
    
    // 搜索路径,参数为NSSearchPathDirectory
    + (NSString *)fw_pathSearch:(NSSearchPathDirectory)directory NS_REFINED_FOR_SWIFT;
    
    // 沙盒路径
    @property (class, nonatomic, copy, readonly) NSString *fw_pathHome NS_REFINED_FOR_SWIFT;
    
    // 文档路径,iTunes会同步备份
    @property (class, nonatomic, copy, readonly) NSString *fw_pathDocument NS_REFINED_FOR_SWIFT;
    
    // 缓存路径,系统不会删除,iTunes会删除
    @property (class, nonatomic, copy, readonly) NSString *fw_pathCaches NS_REFINED_FOR_SWIFT;
    
    // Library路径
    @property (class, nonatomic, copy, readonly) NSString *fw_pathLibrary NS_REFINED_FOR_SWIFT;
    
    // 配置路径,配置文件保存位置
    @property (class, nonatomic, copy, readonly) NSString *fw_pathPreference NS_REFINED_FOR_SWIFT;
    
    // 临时路径,App退出后可能会删除
    @property (class, nonatomic, copy, readonly) NSString *fw_pathTmp NS_REFINED_FOR_SWIFT;
    
    // bundle路径,不可写
    @property (class, nonatomic, copy, readonly) NSString *fw_pathBundle NS_REFINED_FOR_SWIFT;
    
    // 资源路径,不可写
    @property (class, nonatomic, copy, readonly) NSString *fw_pathResource NS_REFINED_FOR_SWIFT;
    
    // 绝对路径缩短为波浪线路径
    + (NSString *)fw_abbreviateTildePath:(NSString *)path NS_REFINED_FOR_SWIFT;
    
    // 波浪线路径展开为绝对路径
    + (NSString *)fw_expandTildePath:(NSString *)path NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Size
    
    // 获取目录大小,单位:B
    + (unsigned long long)fw_folderSize:(NSString *)folderPath NS_REFINED_FOR_SWIFT;
    
    // 获取磁盘可用空间,单位:MB
    @property (class, nonatomic, assign, readonly) double fw_availableDiskSize NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Addition
    
    // 禁止iCloud备份路径
    + (BOOL)fw_skipBackup:(NSString *)path NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSNumber (FWApplication)
    
    /// 转换为CGFloat
    @property (nonatomic, assign, readonly) CGFloat fw_CGFloatValue NS_REFINED_FOR_SWIFT;
    
    /// 四舍五入,去掉末尾0,最多digit位,小数分隔符为.,分组分隔符为空,示例:12345.6789 => 12345.68
    - (NSString *)fw_roundString:(NSInteger)digit NS_REFINED_FOR_SWIFT;
    
    /// 取上整,去掉末尾0,最多digit位,小数分隔符为.,分组分隔符为空,示例:12345.6789 => 12345.68
    - (NSString *)fw_ceilString:(NSInteger)digit NS_REFINED_FOR_SWIFT;
    
    /// 取下整,去掉末尾0,最多digit位,小数分隔符为.,分组分隔符为空,示例:12345.6789 => 12345.67
    - (NSString *)fw_floorString:(NSInteger)digit NS_REFINED_FOR_SWIFT;
    
    /// 四舍五入,去掉末尾0,最多digit位,示例:12345.6789 => 12345.68
    - (NSNumber *)fw_roundNumber:(NSUInteger)digit NS_REFINED_FOR_SWIFT;
    
    /// 取上整,去掉末尾0,最多digit位,示例:12345.6789 => 12345.68
    - (NSNumber *)fw_ceilNumber:(NSUInteger)digit NS_REFINED_FOR_SWIFT;
    
    /// 取下整,去掉末尾0,最多digit位,示例:12345.6789 => 12345.67
    - (NSNumber *)fw_floorNumber:(NSUInteger)digit NS_REFINED_FOR_SWIFT;
    
    @end

Lock

  • 可使用NS_UNAVAILABLE标记方法不可用,NS_DESIGNATED_INITIALIZER标记默认init方法。 注意load可能被子类super调用导致调用多次,需dispatch_once避免;而initialize如果子类不实现,默认会调用父类initialize,也会导致调用多次,可判断class或dispatch_once避免

    See more

    Declaration

    Objective-C

    @interface NSObject (FWApplication)
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSString (FWApplication)
    
    #pragma mark - Pinyin
    
    /**
     *  中文转拼音并进行比较
     *
     *  @param string 中文字符串
     */
    - (NSComparisonResult)fw_pinyinCompare:(NSString *)string NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Regex
    
    /**
     *  安全截取字符串。解决末尾半个Emoji问题(半个Emoji调UTF8String为NULL,导致MD5签名等失败)
     *
     *  @param index 目标索引
     */
    - (NSString *)fw_emojiSubstring:(NSUInteger)index NS_REFINED_FOR_SWIFT;
    
    /**
     *  正则搜索子串
     *
     *  @param regex 正则表达式
     */
    - (nullable NSString *)fw_regexSubstring:(NSString *)regex NS_REFINED_FOR_SWIFT;
    
    /**
     *  正则替换字符串
     *
     *  @param regex  正则表达式
     *  @param string 替换模板,如"头部$1中部$2尾部"
     *
     *  @return 替换后的字符串
     */
    - (NSString *)fw_regexReplace:(NSString *)regex withString:(NSString *)string NS_REFINED_FOR_SWIFT;
    
    /**
     *  正则匹配回调
     *
     *  @param regex 正则表达式
     *  @param block 回调句柄。range从大至小,方便replace
     */
    - (void)fw_regexMatches:(NSString *)regex withBlock:(void (^)(NSRange range))block NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Html
    
    /**
     转义Html,如"a<"转义为"a&lt;"
     
     @return 转义后的字符串
     */
    @property (nonatomic, copy, readonly) NSString *fw_escapeHtml NS_REFINED_FOR_SWIFT;
    
    // 创建一个UUID字符串,示例:"D1178E50-2A4D-4F1F-9BD3-F6AAB00E06B1"。也可调用NSUUID.UUID.UUIDString
    @property (class, nonatomic, copy, readonly) NSString *fw_UUIDString NS_REFINED_FOR_SWIFT;
    
    @end

NSString+FWFormat

    • 正则表达式简单说明
    • 语法: . 匹配除换行符以外的任意字符 \w 匹配字母或数字或下划线或汉字 \s 匹配任意的空白符 \d 匹配数字 \b 匹配单词的开始或结束 ^ 匹配字符串的开始 $ 匹配字符串的结束
    • 重复零次或更多次
    • 重复一次或更多次 ? 重复零次或一次 {n} 重复n次 {n,} 重复n次或更多次 {n,m} 重复n到m次 \W 匹配任意不是字母,数字,下划线,汉字的字符 \S 匹配任意不是空白符的字符 \D 匹配任意非数字的字符 \B 匹配不是单词开头或结束的位置 [^x] 匹配除了x以外的任意字符 [^aeiou]匹配除了aeiou这几个字母以外的任意字符 *? 重复任意次,但尽可能少重复 +? 重复1次或更多次,但尽可能少重复 ?? 重复0次或1次,但尽可能少重复 {n,m}? 重复n到m次,但尽可能少重复 {n,}? 重复n次以上,但尽可能少重复 \a 报警字符(打印它的效果是电脑嘀一声) \b 通常是单词分界位置,但如果在字符类里使用代表退格 \t 制表符,Tab \r 回车 \v 竖向制表符 \f 换页符 \n 换行符 \e Escape \0nn ASCII代码中八进制代码为nn的字符 \xnn ASCII代码中十六进制代码为nn的字符 \unnnn Unicode代码中十六进制代码为nnnn的字符 \cN ASCII控制字符。比如\cC代表Ctrl+C \A 字符串开头(类似^,但不受处理多行选项的影响) \Z 字符串结尾或行尾(不受处理多行选项的影响) \z 字符串结尾(类似$,但不受处理多行选项的影响) \G 当前搜索的开头 \p{name} Unicode中命名为name的字符类,例如\p{IsGreek} (?>exp) 贪婪子表达式 (?-exp) 平衡组 (?im-nsx:exp) 在子表达式exp中改变处理选项 (?im-nsx) 为表达式后面的部分改变处理选项 (?(exp)yes|no) 把exp当作零宽正向先行断言,如果在这个位置能匹配,使用yes作为此组的表达式;否则使用no (?(exp)yes) 同上,只是使用空表达式作为no (?(name)yes|no) 如果命名为name的组捕获到了内容,使用yes作为表达式;否则使用no (?(name)yes) 同上,只是使用空表达式作为no

    捕获 (exp) 匹配exp,并捕获文本到自动命名的组里 (?exp) 匹配exp,并捕获文本到名称为name的组里,也可以写成(?‘name'exp) (?:exp) 匹配exp,不捕获匹配的文本,也不给此分组分配组号 零宽断言 (?=exp) 匹配exp前面的位置 (?<=exp) 匹配exp后面的位置 (?!exp) 匹配后面跟的不是exp的位置 (?<!exp) 匹配前面不是exp的位置 注释 (?#comment) 这种类型的分组不对正则表达式的处理产生任何影响,用于提供注释让人阅读

    • 表达式:(?0\d{2}[) -]?\d{8}
    • 这个表达式可以匹配几种格式的电话号码,像(010)88886666,或022-22334455,或02912345678等。
    • 我们对它进行一些分析吧:
    • 首先是一个转义字符(,它能出现0次或1次(?),然后是一个0,后面跟着2个数字(\d{2}),然后是)或-或空格中的一个,它出现1次或不出现(?),
    • 最后是8个数字(\d{8})
    See more

    Declaration

    Objective-C

    @interface NSString (FWFormat)
  • 第三方URL生成器,可先判断canOpenURL,再openURL,需添加对应URL SCHEME到LSApplicationQueriesSchemes配置数组

    See more

    Declaration

    Objective-C

    @interface NSURL (FWApplication)
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface NSURLRequest (FWApplication)
    
    /**
     生成对应curl命令,方便调试和测试
     */
    - (NSString *)fw_curlCommand NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIBezierPath (FWApplication)
    
    // 绘制形状图片,自定义画笔宽度、画笔颜色、填充颜色,填充颜色为nil时不执行填充
    - (nullable UIImage *)fw_shapeImage:(CGSize)size
                         strokeWidth:(CGFloat)strokeWidth
                         strokeColor:(UIColor *)strokeColor
                           fillColor:(nullable UIColor *)fillColor NS_REFINED_FOR_SWIFT;
    
    // 绘制形状Layer,自定义画笔宽度、画笔颜色、填充颜色,填充颜色为nil时不执行填充
    - (CAShapeLayer *)fw_shapeLayer:(CGRect)rect
                     strokeWidth:(CGFloat)strokeWidth
                     strokeColor:(UIColor *)strokeColor
                       fillColor:(nullable UIColor *)fillColor NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Bezier
    
    // 根据点计算折线路径(NSValue点)
    + (UIBezierPath *)fw_linesWithPoints:(NSArray *)points NS_REFINED_FOR_SWIFT;
    
    // 根据点计算贝塞尔曲线路径
    + (UIBezierPath *)fw_quadCurvedPathWithPoints:(NSArray *)points NS_REFINED_FOR_SWIFT;
    
    // 计算两点的中心点
    + (CGPoint)fw_middlePoint:(CGPoint)p1 withPoint:(CGPoint)p2 NS_REFINED_FOR_SWIFT;
    
    // 计算两点的贝塞尔曲线控制点
    + (CGPoint)fw_controlPoint:(CGPoint)p1 withPoint:(CGPoint)p2 NS_REFINED_FOR_SWIFT;
    
    // 将角度(0~360)转换为弧度,周长为2*M_PI*r
    + (CGFloat)fw_radianWithDegree:(CGFloat)degree NS_REFINED_FOR_SWIFT;
    
    // 将弧度转换为角度(0~360)
    + (CGFloat)fw_degreeWithRadian:(CGFloat)radian NS_REFINED_FOR_SWIFT;
    
    // 根据滑动方向计算rect的线段起点、终点中心点坐标数组(示范:田)。默认从上到下滑动
    + (NSArray<NSValue *> *)fw_linePointsWithRect:(CGRect)rect direction:(UISwipeGestureRecognizerDirection)direction NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Shape
    
    // "🔴" 圆的形状,0~1,degree为起始角度,如-90度
    + (UIBezierPath *)fw_shapeCircle:(CGRect)frame percent:(float)percent degree:(CGFloat)degree NS_REFINED_FOR_SWIFT;
    
    // "❤️" 心的形状
    + (UIBezierPath *)fw_shapeHeart:(CGRect)frame NS_REFINED_FOR_SWIFT;
    
    // "⭐" 星星的形状
    + (UIBezierPath *)fw_shapeStar:(CGRect)frame NS_REFINED_FOR_SWIFT;
    
    // "⭐⭐⭐⭐⭐" 几颗星星的形状
    + (UIBezierPath *)fw_shapeStars:(NSUInteger)count frame:(CGRect)frame spacing:(CGFloat)spacing NS_REFINED_FOR_SWIFT;
    
    // "➕" 加号形状
    + (UIBezierPath *)fw_shapePlus:(CGRect)frame NS_REFINED_FOR_SWIFT;
    
    // "➖" 减号形状
    + (UIBezierPath *)fw_shapeMinus:(CGRect)frame NS_REFINED_FOR_SWIFT;
    
    // "✖" 叉叉形状(错误)
    + (UIBezierPath *)fw_shapeCross:(CGRect)frame NS_REFINED_FOR_SWIFT;
    
    // "✔" 检查形状(正确)
    + (UIBezierPath *)fw_shapeCheck:(CGRect)frame NS_REFINED_FOR_SWIFT;
    
    // "<" 折叠形状,可指定方向
    + (UIBezierPath *)fw_shapeFold:(CGRect)frame direction:(UISwipeGestureRecognizerDirection)direction NS_REFINED_FOR_SWIFT;
    
    // "⬅" 箭头形状,可指定方向
    + (UIBezierPath *)fw_shapeArrow:(CGRect)frame direction:(UISwipeGestureRecognizerDirection)direction NS_REFINED_FOR_SWIFT;
    
    // "🔺" 三角形形状,可指定方向
    + (UIBezierPath *)fw_shapeTriangle:(CGRect)frame direction:(UISwipeGestureRecognizerDirection)direction NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIButton (FWApplication)
    
    /// 开始按钮倒计时,从window移除时自动取消。等待时按钮disabled,非等待时enabled。时间支持格式化,示例:重新获取(%lds)
    - (dispatch_source_t)fw_startCountDown:(NSInteger)seconds title:(NSString *)title waitTitle:(NSString *)waitTitle NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UICollectionViewFlowLayout (FWApplication)
    
    /// 设置Header和Footer是否悬停,支持iOS9+
    - (void)fw_hoverWithHeader:(BOOL)header footer:(BOOL)footer NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIColor (FWApplication)
    
    #pragma mark - Color
    
    // 以指定模式添加混合颜色
    - (UIColor *)fw_addColor:(UIColor *)color blendMode:(CGBlendMode)blendMode NS_REFINED_FOR_SWIFT;
    
    // 当前颜色的反色。http://stackoverflow.com/questions/5893261/how-to-get-inverse-color-from-uicolor
    @property (nonatomic, strong, readonly) UIColor *fw_inverseColor NS_REFINED_FOR_SWIFT;
    
    // 判断当前颜色是否为深色。http://stackoverflow.com/questions/19456288/text-color-based-on-background-image
    @property (nonatomic, assign, readonly) BOOL fw_isDarkColor NS_REFINED_FOR_SWIFT;
    
    // 当前颜色修改亮度比率的颜色
    - (UIColor *)fw_brightnessColor:(CGFloat)ratio NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Image
    
    // 从整个图像初始化UIColor
    + (UIColor *)fw_colorWithImage:(UIImage *)image NS_REFINED_FOR_SWIFT;
    
    // 从图像的某个点初始化UIColor
    + (nullable UIColor *)fw_colorWithImage:(UIImage *)image point:(CGPoint)point NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Gradient
    
    /**
     创建渐变颜色,支持四个方向,默认向下Down
     
     @param size 渐变尺寸,非渐变边可以设置为1。如CGSizeMake(1, 50)
     @param colors 渐变颜色,CGColor数组,如:@[(__bridge id)[UIColor redColor].CGColor, (__bridge id)[UIColor blueColor].CGColor]
     @param locations 渐变位置,传NULL时均分,如:CGFloat locations[] = {0.0, 1.0};
     @param direction 渐变方向,自动计算startPoint和endPoint,支持四个方向,默认向下Down
     @return 渐变色
     */
    + (UIColor *)fw_gradientColorWithSize:(CGSize)size
                                  colors:(NSArray *)colors
                               locations:(nullable const CGFloat *)locations
                               direction:(UISwipeGestureRecognizerDirection)direction NS_REFINED_FOR_SWIFT;
    
    /**
     创建渐变颜色
     
     @param size 渐变尺寸,非渐变边可以设置为1。如CGSizeMake(1, 50)
     @param colors 渐变颜色,CGColor数组,如:@[(__bridge id)[UIColor redColor].CGColor, (__bridge id)[UIColor blueColor].CGColor]
     @param locations 渐变位置,传NULL时均分,如:CGFloat locations[] = {0.0, 1.0};
     @param startPoint 渐变开始点,需要根据rect计算
     @param endPoint 渐变结束点,需要根据rect计算
     @return 渐变色
     */
    + (UIColor *)fw_gradientColorWithSize:(CGSize)size
                                  colors:(NSArray *)colors
                               locations:(nullable const CGFloat *)locations
                              startPoint:(CGPoint)startPoint
                                endPoint:(CGPoint)endPoint NS_REFINED_FOR_SWIFT;
    
    @end
  • 防重复点击可以手工控制enabled或userInteractionEnabled,如request开始时禁用,结束时启用等

    See more

    Declaration

    Objective-C

    @interface UIControl (FWApplication)
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIDevice (FWApplication)
    
    #pragma mark - Jailbroken
    
    // 是否越狱
    @property (class, nonatomic, assign, readonly) BOOL fw_isJailbroken NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Network
    
    // 本地IP地址
    @property (class, nonatomic, copy, readonly, nullable) NSString *fw_ipAddress NS_REFINED_FOR_SWIFT;
    
    // 本地主机名称
    @property (class, nonatomic, copy, readonly, nullable) NSString *fw_hostName NS_REFINED_FOR_SWIFT;
    
    // 手机运营商名称
    @property (class, nonatomic, copy, readonly, nullable) NSString *fw_carrierName NS_REFINED_FOR_SWIFT;
    
    // 手机蜂窝网络类型,仅区分2G|3G|4G|5G
    @property (class, nonatomic, copy, readonly, nullable) NSString *fw_networkType NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIFont (FWApplication)
    
    #pragma mark - Font
    
    /// 是否是粗体
    @property (nonatomic, assign, readonly) BOOL fw_isBold NS_REFINED_FOR_SWIFT;
    
    /// 是否是斜体
    @property (nonatomic, assign, readonly) BOOL fw_isItalic NS_REFINED_FOR_SWIFT;
    
    /// 当前字体的粗体字体
    @property (nonatomic, strong, readonly) UIFont *fw_boldFont NS_REFINED_FOR_SWIFT;
    
    /// 当前字体的非粗体字体
    @property (nonatomic, strong, readonly) UIFont *fw_nonBoldFont NS_REFINED_FOR_SWIFT;
    
    /// 当前字体的斜体字体
    @property (nonatomic, strong, readonly) UIFont *fw_italicFont NS_REFINED_FOR_SWIFT;
    
    /// 当前字体的非斜体字体
    @property (nonatomic, strong, readonly) UIFont *fw_nonItalicFont NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Height
    
    // 字体空白高度(上下之和)
    @property (nonatomic, assign, readonly) CGFloat fw_spaceHeight NS_REFINED_FOR_SWIFT;
    
    // 根据字体计算指定倍数行间距的实际行距值(减去空白高度),示例:行间距为0.5倍实际高度
    - (CGFloat)fw_lineSpacingWithMultiplier:(CGFloat)multiplier NS_REFINED_FOR_SWIFT;
    
    // 根据字体计算指定倍数行高的实际行高值(减去空白高度),示例:行高为1.5倍实际高度
    - (CGFloat)fw_lineHeightWithMultiplier:(CGFloat)multiplier NS_REFINED_FOR_SWIFT;
    
    /// 计算当前字体与指定字体居中对齐的偏移值
    - (CGFloat)fw_baselineOffset:(UIFont *)font NS_REFINED_FOR_SWIFT;
    
    @end
  • 注意CGContextDrawImage如果图片尺寸太大会导致内存不足闪退(如高斯模糊效果),建议先压缩再调用

    See more

    Declaration

    Objective-C

    @interface UIImage (FWApplication)
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIImageView (FWApplication)
    
    #pragma mark - Mode
    
    // 设置图片模式为ScaleAspectFill,自动拉伸不变形,超过区域隐藏。可通过appearance统一设置
    - (void)fw_setContentModeAspectFill UI_APPEARANCE_SELECTOR NS_REFINED_FOR_SWIFT;
    
    // 设置指定图片模式,超过区域隐藏。可通过appearance统一设置
    - (void)fw_setContentMode:(UIViewContentMode)contentMode UI_APPEARANCE_SELECTOR NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Face
    
    // 优化图片人脸显示,参考:https://github.com/croath/UIImageView-BetterFace
    - (void)fw_faceAware NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Reflect
    
    // 倒影效果
    - (void)fw_reflect NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Watermark
    
    // 图片水印
    - (void)fw_setImage:(UIImage *)image watermarkImage:(UIImage *)watermarkImage inRect:(CGRect)rect NS_REFINED_FOR_SWIFT;
    
    // 文字水印,指定区域
    - (void)fw_setImage:(UIImage *)image watermarkString:(NSAttributedString *)watermarkString inRect:(CGRect)rect NS_REFINED_FOR_SWIFT;
    
    // 文字水印,指定坐标
    - (void)fw_setImage:(UIImage *)image watermarkString:(NSAttributedString *)watermarkString atPoint:(CGPoint)point NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UNUserNotificationCenter (FWApplication)
    
    // 创建本地通知,badge为0时不显示(nil时不修改),soundName为default时为默认声音
    + (UNMutableNotificationContent *)fw_localNotificationWithTitle:(nullable NSString *)title subtitle:(nullable NSString *)subtitle body:(nullable NSString *)body userInfo:(nullable NSDictionary *)userInfo category:(nullable NSString *)category badge:(nullable NSNumber *)badge soundName:(nullable NSString *)soundName block:(nullable void (NS_NOESCAPE ^)(UNMutableNotificationContent *content))block NS_REFINED_FOR_SWIFT;
    
    // 注册本地通知,trigger为nil时立即触发,iOS10+
    + (void)fw_registerLocalNotification:(NSString *)identifier content:(UNNotificationContent *)content trigger:(nullable UNNotificationTrigger *)trigger NS_REFINED_FOR_SWIFT;
    
    // 删除未发出的本地通知,iOS10+
    + (void)fw_removePendingNotification:(NSArray<NSString *> *)identifiers NS_REFINED_FOR_SWIFT;
    
    // 删除所有未发出的本地通知,iOS10+
    + (void)fw_removeAllPendingNotifications NS_REFINED_FOR_SWIFT;
    
    // 删除已发出的本地通知,iOS10+
    + (void)fw_removeDeliveredNotification:(NSArray<NSString *> *)identifiers NS_REFINED_FOR_SWIFT;
    
    // 删除所有已发出的本地通知,iOS10+
    + (void)fw_removeAllDeliveredNotifications NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UINavigationBar (FWApplication)
    
    /// 导航栏内容视图,iOS11+才存在,显示item和titleView等
    @property (nonatomic, readonly, nullable) UIView *fw_contentView NS_REFINED_FOR_SWIFT;
    
    /// 导航栏大标题视图,显示时才有值。如果要设置背景色,可使用fwBackgroundView.backgroundColor
    @property (nonatomic, readonly, nullable) UIView *fw_largeTitleView NS_REFINED_FOR_SWIFT;
    
    /// 导航栏大标题高度,与是否隐藏无关
    @property (class, nonatomic, readonly, assign) CGFloat fw_largeTitleHeight NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIToolbar (FWApplication)
    
    /// 工具栏内容视图,iOS11+才存在,显示item等
    @property (nonatomic, readonly, nullable) UIView *fw_contentView NS_REFINED_FOR_SWIFT;
    
    /// 工具栏背景视图,显示背景色和背景图片等。如果标签栏同时显示,背景视图高度也会包含标签栏高度
    @property (nonatomic, readonly, nullable) UIView *fw_backgroundView NS_REFINED_FOR_SWIFT;
    
    @end
  • 添加顶部下拉图片时,只需将该子view添加到scrollView最底层(如frame方式添加inset视图),再实现效果即可。

    See more

    Declaration

    Objective-C

    @interface UIScrollView (FWApplication)

UIGestureRecognizer+FWApplication

  • gestureRecognizerShouldBegin:是否继续进行手势识别,默认YES shouldRecognizeSimultaneouslyWithGestureRecognizer: 是否支持多手势触发。默认NO shouldRequireFailureOfGestureRecognizer:是否otherGestureRecognizer触发失败时,才开始触发gestureRecognizer。返回YES,第一个手势失败 shouldBeRequiredToFailByGestureRecognizer:在otherGestureRecognizer识别其手势之前,是否gestureRecognizer必须触发失败。返回YES,第二个手势失败

    See more

    Declaration

    Objective-C

    @interface UIGestureRecognizer (FWApplication)
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIPanGestureRecognizer (FWApplication)
    
    // 当前滑动方向,如果多个方向滑动,取绝对值较大的一方,失败返回0
    @property (nonatomic, assign, readonly) UISwipeGestureRecognizerDirection fw_swipeDirection NS_REFINED_FOR_SWIFT;
    
    // 当前滑动进度,滑动绝对值相对于手势视图的宽或高
    @property (nonatomic, assign, readonly) CGFloat fw_swipePercent NS_REFINED_FOR_SWIFT;
    
    // 计算指定方向的滑动进度
    - (CGFloat)fw_swipePercentOfDirection:(UISwipeGestureRecognizerDirection)direction NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UISearchBar (FWApplication)
    
    // 自定义内容边距,可调整左右距离和TextField高度,未设置时为系统默认
    @property (nonatomic, assign) UIEdgeInsets fw_contentInset NS_REFINED_FOR_SWIFT;
    
    // 自定义取消按钮边距,未设置时为系统默认
    @property (nonatomic, assign) UIEdgeInsets fw_cancelButtonInset NS_REFINED_FOR_SWIFT;
    
    // 输入框内部视图
    @property (nullable, nonatomic, weak, readonly) UITextField *fw_textField NS_REFINED_FOR_SWIFT;
    
    // 取消按钮内部视图,showsCancelButton开启后才存在
    @property (nullable, nonatomic, weak, readonly) UIButton *fw_cancelButton NS_REFINED_FOR_SWIFT;
    
    // 设置整体背景色
    @property (nonatomic, strong, nullable) UIColor *fw_backgroundColor NS_REFINED_FOR_SWIFT;
    
    // 设置输入框背景色
    @property (nonatomic, strong, nullable) UIColor *fw_textFieldBackgroundColor NS_REFINED_FOR_SWIFT;
    
    // 设置搜索图标离左侧的偏移位置,非居中时生效
    @property (nonatomic, assign) CGFloat fw_searchIconOffset NS_REFINED_FOR_SWIFT;
    
    // 设置搜索文本离左侧图标的偏移位置
    @property (nonatomic, assign) CGFloat fw_searchTextOffset NS_REFINED_FOR_SWIFT;
    
    // 设置TextField搜索图标(placeholder)是否居中,否则居左
    @property (nonatomic, assign) BOOL fw_searchIconCenter NS_REFINED_FOR_SWIFT;
    
    // 强制取消按钮一直可点击,需在showsCancelButton设置之后生效。默认SearchBar失去焦点之后取消按钮不可点击
    @property (nonatomic, assign) BOOL fw_forceCancelButtonEnabled NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UISwitch (FWApplication)
    
    /**
     切换开关状态
     */
    - (void)fw_toggle:(BOOL)animated NS_REFINED_FOR_SWIFT;
    
    @end

UITextField+FWApplication

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UITextField (FWApplication)
    
    #pragma mark - Menu
    
    // 是否禁用长按菜单(拷贝、选择、粘贴等),默认NO
    @property (nonatomic, assign) BOOL fw_menuDisabled NS_REFINED_FOR_SWIFT;
    
    #pragma mark - Select
    
    // 自定义光标颜色
    @property (nonatomic, strong, null_resettable) UIColor *fw_cursorColor NS_REFINED_FOR_SWIFT;
    
    // 自定义光标大小,不为0才会生效,默认zero不生效
    @property (nonatomic, assign) CGRect fw_cursorRect NS_REFINED_FOR_SWIFT;
    
    // 获取及设置当前选中文字范围
    @property (nonatomic, assign) NSRange fw_selectedRange NS_REFINED_FOR_SWIFT;
    
    // 移动光标到最后
    - (void)fw_selectAllRange NS_REFINED_FOR_SWIFT;
    
    // 移动光标到指定位置,兼容动态text赋值
    - (void)fw_moveCursor:(NSInteger)offset NS_REFINED_FOR_SWIFT;
    
    @end

CALayer+FWLayer

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface CALayer (FWLayer)
    
    // 设置阴影颜色、偏移和半径
    - (void)fw_setShadowColor:(nullable UIColor *)color
                      offset:(CGSize)offset
                      radius:(CGFloat)radius NS_REFINED_FOR_SWIFT;
    
    @end

CAGradientLayer+FWLayer

  • Undocumented

    See more

    Declaration

    Objective-C

    @interface CAGradientLayer (FWLayer)
    
    /**
     *  创建渐变层,需手工addLayer
     *
     *  @param frame      渐变区域
     *  @param colors     渐变颜色,CGColor数组,如[黑,白,黑]
     *  @param locations  渐变位置,0~1,如[0.25, 0.5, 0.75]对应颜色为[0-0.25黑,0.25-0.5黑渐变白,0.5-0.75白渐变黑,0.75-1黑]
     *  @param startPoint 渐变开始点,设置渐变方向,左上点为(0,0),右下点为(1,1)
     *  @param endPoint   渐变结束点
     *  @return 渐变Layer
     */
    + (CAGradientLayer *)fw_gradientLayer:(CGRect)frame
                                  colors:(NSArray *)colors
                               locations:(nullable NSArray<NSNumber *> *)locations
                              startPoint:(CGPoint)startPoint
                                endPoint:(CGPoint)endPoint NS_REFINED_FOR_SWIFT;
    
    @end
  • Undocumented

    See more

    Declaration

    Objective-C

    @interface UIWindow (FWApplication)
    
    /// 关闭所有弹出控制器,完成时回调。如果没有present控制器,直接回调
    - (void)fw_dismissViewControllers:(nullable void (^)(void))completion NS_REFINED_FOR_SWIFT;
    
    /// 选中并获取指定索引TabBar根视图控制器,适用于Tabbar包含多个Navigation结构,找不到返回nil
    - (nullable __kindof UIViewController *)fw_selectTabBarIndex:(NSUInteger)index NS_REFINED_FOR_SWIFT;
    
    /// 选中并获取指定类TabBar根视图控制器,适用于Tabbar包含多个Navigation结构,找不到返回nil
    - (nullable __kindof UIViewController *)fw_selectTabBarController:(Class)viewController NS_REFINED_FOR_SWIFT;
    
    /// 选中并获取指定条件TabBar根视图控制器,适用于Tabbar包含多个Navigation结构,找不到返回nil
    - (nullable __kindof UIViewController *)fw_selectTabBarBlock:(BOOL (NS_NOESCAPE ^)(__kindof UIViewController *viewController))block NS_REFINED_FOR_SWIFT;
    
    @end