- 目录路径:MCComponentExtension/Bundle/Bundle+Extension
获取bundle的路径。
Bundle.MCGetBundlePath(bundleName:String)
加载指定bundle路径下的图片
Bundle.MCLoadImageFromBundleName(bundleName:String,imageName:String)
- 目录路径:MCComponentExtension/Int/Int+Extension
转换类型
| 转换类型 |
Int |
String |
| Int |
\ |
toInt |
| String |
toString |
\ |
| Float |
toFloat |
toFloat |
| Double |
toDouble |
toDouble |
| Number |
toNumber |
toNumber |
| YuanRMB(String) |
toYuanRMB |
\ |
String 设置属性
| String设置 |
String |
| MCMD5(MD5加密) |
MCMD5 |
| 字符串高度 |
MCGetHeight |
| 字符串宽度 |
MCGetWidth |
| 截取指定的区间 |
MCCutRange(location:Int, length:Int) |
| 截取从头截取到指定index |
MCCutFromPrefixToIndex(index:Int) |
| 截取从指定位置截取到尾部 |
MCCutToSuffixFromIndex(index:Int) |
String 设置文本属性
| String文本 |
String |
返回类型 |
| 文本的颜色 |
MCSetMutableColor(color:UIColor,range:NSRange) |
NSAttributedString |
| 文本的字体大小 |
MCSetMutableFont(font:CGFloat,range:NSRange) |
NSAttributedString |
| 文本的字体大小和颜色 |
MCSetMutableFontAndColor(font:CGFloat,fontRange:NSRange,color:UIColor,colorRange:NSRange) |
NSAttributedString |
| 文本的行间距 |
MCSetLineSpace(lineSpace:CGFloat) |
NSAttributedString |
| 删除线 |
MCSetDeleteLine(color:UIColor) |
NSAttributedString |
| 图文详情 |
MCSetTextAttachment(image:UIImage,imageFrame:CGRect) |
NSMutableAttributedString |
判断是否是11位
String.MCPhoneNumberIsTrue(str:String) // 返回值为bool
字符串转字典
String.MCCreateDictionary() // 返回值为NSDictionary
生成二维码图片logoImage 中间的图片logo
String.MCCreateQRImage(logoImage:UIImage) // 返回值为UIImage
- 目录路径:MCComponentExtension/MCLoading/MCLoading+Extension
提示框,不传参数(用默认参数) 显示一个菊花loading,切换图片的时间间隔(ms),timeInterval,images 图片集合
MCLoading.loading(images: [UIImage], timeInterval: Int)
提示框
| 功能 |
提示框 |
默认(时间2秒,字体14) |
| 显示纯文字 |
MCLoading.text(String, autoClearTime: CGFloat, font: CGFloat) |
MCLoading.text(String) |
| 成功的提示 |
MCLoading.success(String, autoClearTime: CGFloat, font: CGFloat) |
MCLoading.success(String) |
| 失败的提示 |
MCLoading.failure(String, autoClearTime: CGFloat, font: CGFloat) |
MCLoading.failure(String) |
| 普通x消息的提示 |
MCLoading.info(String, autoClearTime: CGFloat, font: CGFloat) |
MCLoadinginfo(String) |
| 关闭所有 |
MCLoading.remove() |
\ |
| 顶部状态栏消息的弹出 |
MCLoading.textOnStatusBar(String, autoClearTime: CGFloat, font: CGFloat) |
MCLoading.textOnStatusBar(String) |
- 目录路径:MCComponentExtension/NotificationCenter/Extension+NotificationCenter
发送通知
NotificationCenter.shared.post(MCNotification.wxLogin)
/*
* 这里有几个固定的名称
* /// 微信登录
* case wxLogin
/// 支付结果
* case payResult
/// 刷新所有数据
* case reloadAllData
/// 添加收货地址
* case addAddress
/// 修改收货地址
* case modifyAddress
/// 订单状态发生改变
* case orderStatusChange
***** 也可以自定义 ********
*/
// 创建通知中心
NotificationCenter.shared.addObserver(name: MCNotification, vc: Any, selector: Selector, object: Any?)
// 移除通知
NotificationCenter.shared.remove(MCNotification, vc: Any)
- 目录路径:MCComponentExtension/UIAlertController/UIAlertController+Extension
弹出提示框
| 功能 |
提示框(有按钮) |
是否有取消(YES/NO) |
| 在指定控制器上显示提示框 |
UIAlertController.MCShowAlert(title: String, confirm: (UIAlertAction) -> Void) |
NO |
| 在根视图控制器上显示提示框 |
UIAlertController.MCShowAlert(title: String, message: String = "",confirm: ((UIAlertAction)->Void)?) |
NO |
| 在指定控制器上显示确认框 |
UIAlertController.MCShowConfirm( title: String, message: String, on vc:self , confirm: ((UIAlertAction)->Void)?,cancel: ((UIAlertAction)->Void)?) |
YES |
| 在根视图控制器上显示确认框 |
UIAlertController.MCLoading.MCShowConfirm( title: String ,message: String = "", confirm: ((UIAlertAction)->Void)?,cancel: ((UIAlertAction)->Void)? = nil) |
YES |
| 在指定控制器上显示actionSheet(AlertAction根据数组数量决定) |
UIAlertController.MCShowActionSheetCustom( title: String ,message: String? = nil, on vc : UIViewController, items:[String],confirm : ((Int,String) -> Void)?, cancel: ((UIAlertAction)->Void)? = nil) |
YES |
| 在指定控制器上显示拍照或者相册 |
UIAlertController.MCLoadingMCShowActionSheet_pictureWay(on vc :self,hander : ((String) -> Void)?) |
NO(有相册) |
| 微信/朋友圈的ActionSheet 在指定控制器上显示拍照或者相册 |
UIAlertController.MCShowActionSheet_shareWay(on vc : UIViewController,hander : ((String) -> Void)?) |
NO(有分享) |
- 目录路径:MCComponentExtension/UIBarButtonItem/UIBarButtonItem+Extension
导航栏左右边的图片
self.navigationItem.leftBarButtonItem = UIBarButtonItem.MCSetImage(UIImage.init(named: "Reuse_back"), target: self, selector: #selector(leftbackHander))
导航栏左右边的文字
navigationItem.rightBarButtonItem = UIBarButtonItem.MCSetText("提交", target: self, selector: #selector(rightItemEvent))
- 目录路径:MCComponentExtension/UIColor/UIColor+Extension
颜色的封装(例)
text.textColor = UIColor.MCHex(String)
| 颜色 |
方法 |
16进制颜色 |
| 一级标题 |
MCBlackOne |
0x494949 |
| 次级标题 |
MCBlackTwo |
0x666666 |
| 辅助标题 |
MCBlackThree |
0x999999 |
| 未选中的颜色 |
MCUncheck |
0xDADADA |
| 分隔条 (8px) |
MCBar |
0xf2f2f2 |
| 分割线 & 页面背景底色 |
MCLine |
0xf6f6f6 |
| PlaceHolder颜色 |
MCPlaceHolder |
0xCACACC |
| RGB颜色 |
MCRGB(r: CGFloat,g: CGFloat,b: CGFloat) |
\ |
| 16进制的生成颜色 |
MCHex(_ hex: String, _ alpha: CGFloat = 1.0) |
\ |
| 通过颜色生成图片 |
MCCreateImage() |
返回值UIImage |
渐变色
let gradiet = CAGradientLayer.MCCreateLayer(cgColors: [CGColor], direction: CAGradientLayer.CAGradientDirection.vertical)
view.layer.addSublayer(gradiet)
- 目录路径:MCComponentExtension/UIDevice/UIDevice+Extension
系统的封装(例,宽,高,状态栏)
// 例子获取到屏幕的宽
UIDevice.width
| 名称 |
方法 |
类型 |
| 屏幕宽 |
width |
CGFloat |
| 屏幕高 |
height |
CGFloat |
| 状态栏高度 |
statusBarHeight |
CGFloat |
| 导航栏高度 |
navigationBarHeight |
CGFloat |
| tabbar的高度 |
tabBarHeight |
CGFloat |
| 顶部安全区域的高度 |
topSafeAreaHeight |
CGFloat |
| 底部安全区域 |
bottomSafeAreaHeight |
CGFloat |
| 版本号 |
appVersion |
String |
| 构建号 |
appbBuild |
String |
| app的名称 |
appName |
String |
| 工程名 |
appProjectName |
String |
| 获取该app的缓存 |
MCCacheSize() |
String |
| 清理该app的缓存 |
MCClearCache() |
\ |
- 目录路径:MCComponentExtension/UIFont/UIFont+Extension
字体的大小
// 例:复制字体大小 10 - 34 字体大小
UIFont.MC14
// 例:加粗 15 - 22
UIFont.MCBold15
- 目录路径:MCComponentExtension/UIImage/UIImage+Extension
图片裁切,压缩等操作
//压缩上传图片到指定字节
UIImage.MCCompressTo(UIImage)
//重设图片的size
UIImage.MCResize(CGSize)
//通过指定图片最长边,获得等比例的图片size
UIImage.MCZoomByMaxSide(CGFloat)
//裁切指定区域(CGRect)获取图片
UIImage.MCCropByRect(CGRect)
//给图片添加水印图片
UIImage.MCAddWatermark(image:UIImage,scale:CGFloat)
//更改图片颜色 统一渲染为一个纯色。注意图片上透明的使用。
UIImage.MCRenderingByColor(UIColor)
//修复图片旋转
UIImage.MCFixOrientation()
//生成一个替代图
MCPlaceholder (
size :(width:CGFloat,height:CGFloat) = (200,100),
logoImage: UIImage? = UIImage.init(),
bgColor : UIColor = UIColor.init(red: 242/255.0, green: 242/255.0, blue: 242/255.0, alpha: 1)
)
//将一个UIView视图转为图片
UIView.createImage()