通用UI配置,通用工具类
空余时间完善中....
![colorConfig](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/colorConfig.png?raw=true)
self.view.backgroundColor = UIColor.mq_backgroundColor
UIColor.mq_tintColor
UIColor.mq_borderColor
![fontConfig](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/fontConfig.png?raw=true)
颜色:
UIColor.mq_textColorTitle
UIColor.mq_textColorBody
UIColor.mq_textColorMark
字体:
self.lbTitle.font = UIFont.mq_titleFont (mq_bodyFont,mq_markFont)
self.lbTitle.font = UIFont.mq_titleFont(20)
iconfont:
self.lbIconFont.font = UIFont.mq_iconFont(30)
self.lbIconFont.text = "IconFont,\u{e616}"
字号:
UIFont.mq_titleFontSize
FIG1 |
![fig1](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/fig1.png?raw=true) |
![fontConfig](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/navbarConfig.png?raw=true)
AppDelegate:
MQStructs.loadnavBarConfig()
self.mq_navbarAddBarButtonItems(iconFontTexts: ["\u{e612}","\u{e613}"], fontSize: 30, color: UIColor.orange, at: .left)
self.mq_navbarAddBarButtonItems(textNames: ["Call"], font: nil, color: UIColor.white, at: .right)
self.mq_navbarAddBarButtonItems(imageNames: ["r1","r2"], useOriginalColor: true, at: .right)
self.mq_navbarAddBarButtonItem(customView: view, at: .right)
override func mq_leftBarButtonAction(index: Int) {
print("Left Action At Index:\(index)")
}
override func mq_rightBarButtonAction(index: Int) {
print("Right Action At Index:\(index)")
}
self.mq_setnavbarBackgroundColor(UIColor(red: r, green: g, blue: b, alpha: 1.0))
NAV1 |
NAV2 |
![nav1](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/nav1.png?raw=true) |
![nav2](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/nav2.png?raw=true) |
NAV3 |
NAV4 |
![nav3](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/nav3.png?raw=true) |
![nav4](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/nav4.png?raw=true) |
![fontConfig](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/tabbarConfig.png?raw=true)
AppDelegate:
MQStructs.loadtabBarConfig()
1.按钮从plist文件读取:
tabBar?.mq_addChildViewController(demoVC, fromPlistItemIndex: 0)
2.代码配置
let itemInfo = MQTabbarItem()
//Item 标题
itemInfo.title = "不一样"
//未选中图片
itemInfo.normalImage = "tabbarIcon4-normal"
//选中图片
itemInfo.selectedImage = "tabbarIcon4-selected"
//点击tabbar按钮是否present出来
itemInfo.showAsPresent = false
//是否嵌入一层navigationcontroller
itemInfo.embedInNavigation = true
tabBar?.mq_addChildViewController(MQHHViewController(), fromItem: itemInfo)
3.系统方法
tabBar?.addChildViewController(vc)
self.mq_settabbarBackgroundColor(UIColor.clear)
注
如果 showAsPresent = true ,必须实现代理方法
tabBar.delegate = self
extension AppDelegate: UITabBarControllerDelegate {
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
return UITabBarController.mq_tabBarController(tabBarController,shouldSelectViewController:viewController)
}
}
有颜色 |
![tab1](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/tabbar1.png?raw=true) |
无颜色 |
![tab1](https://github.com/AidyBao/BFramework_swift/raw/master/imgs/tabbar2.png?raw=true) |
//相册取
imagePicker.choosePhoto(presentFrom: self) {[unowned self] (image, status) in
if status == .success {
self.imgView.image = image
}else{
if status == .denied {
MQImagePickerUtils.showTips(at: self, type: .choosePhoto)
}else{
MQAlertUtils.showAlert(withTitle: "提示", message: status.description())
}
}
}
//拍照
imagePicker.takePhoto(presentFrom: self) { [unowned self] (image, status) in
if status == .success {
self.imgView.image = image
}else{
if status == .denied {
MQImagePickerUtils.showTips(at: self, type: .takePhoto)
}else {
MQAlertUtils.showAlert(withTitle: "提示", message: status.description())
}
}
}
MQAlertUtils.showAlert(withTitle: "提示", message: errorMsg!)
MQLocationUtils.shareInstance.checkCurrentLocation(completion: { (status, location) in
if status == .success,let location = location {
print("latitude:\(location.coordinate.latitude),longitude:\(location.coordinate.longitude)")
}else{
print(status.description())
}
})
MQDateUtils.currentDateTime(true, timeWithSecond: true)//2017年04月19日 12:01:57
MQDateUtils.currentDate(true)//2017年04月19日
MQDateUtils.currentTime(true)//12:01:57
MQDateUtils.datetimeFromMilliSecond(1492569882000, chineseFormat: true, timeWithSecond: false)//2017年04月19日 10:44
MQDateUtils.dateFromMilliSecond(1492569882000, chineseFormat: false)//2017-04-19
MQDateUtils.timeFromMilliSecond(1492569882000, timeWithSecond: true)//10:44:42
MQDateUtils.milliSecondFromDate("2017/4/19 10:54:48",dateFormat: "YYYY/MM/dd HH:mm:ss")//1492570488000
MQDateUtils.milliSecondFromDate("2017年4月19日 10:54:48",dateFormat: "YYYY年MM月dd日 HH:mm:ss")//1492570488000
MQDateUtils.currentMillisecond()//1492574517213
MQDateUtils.intToTime(123456,componentString: nil)//10°17′36″
Async Request(JSON/String GET/POST)
MQNetwork.asyncRequest(withUrl: "https://itunes.apple.com/search", params: ["term":"qq","limit":"1","entity":"software"], method: .get, completion: { (obj, stringValue) in
print("\(obj ?? "")")
}, timeOut: { (errorMsg) in
print("TimeOut:\(errorMsg)")
}) { (code, errorMsg) in
print("HttpError:\(code) \(errorMsg)")
}
MQNetwork.uploadImage(to: "https://192.168.0.81:8000/upload", images: [UIImage(named:"r1")!,UIImage(named:"r2")!], params: nil, compressRatio: 1, completion: { (obj, string) in
print("\(obj ?? "")")
}, timeOut: { (errorMsg) in
print("TimeOut:\(errorMsg)")
}) { (code, errorMsg) in
print("HttpError:\(code) \(errorMsg)")
}