let tabbarHeight:CGFloat = 49.0
func setupBaseUI(){
self.contentView.translatesAutoresizingMaskIntoConstraints = false
self.lineView.translatesAutoresizingMaskIntoConstraints = false
self.tabBar.translatesAutoresizingMaskIntoConstraints = false
let views = self.ConstraintDictionWithArray(nameArray: [self.contentView,self.lineView,self.tabBar,self.view], object: self);
NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|[contentView]|", options: NSLayoutFormatOptions.alignAllLeft, metrics: nil, views: views))
NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|[tabBar]|", options: NSLayoutFormatOptions.alignAllLeft, metrics: nil, views: views))
NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "V:|[contentView][tabBar(tabbarHeight)]|", options: NSLayoutFormatOptions.alignAllLeft, metrics: ["tabbarHeight":(self.isIphoneX() ? tabbarHeight_iphoneX : tabbarHeight)], views: views))
NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|[lineView]|", options: NSLayoutFormatOptions.alignAllLeft, metrics: nil, views: views))
NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "V:|[lineView(0.5)]", options: NSLayoutFormatOptions.alignAllLeft, metrics: nil, views: views))
}
//MARK: 相当于OC中的NSBinding(因为oc中没有宏定义,没有NSBinding这个宏定义,所以写一个方法代替这个方法)
func ConstraintDictionWithArray(nameArray:Array<UIView>,object:AnyObject) -> Dictionary<String,AnyObject> {
var dict:Dictionary<String,AnyObject> = [:]
var count:UInt32 = 0
let ivars = class_copyIvarList(object.classForCoder, &count)
for i in 0...Int(count) {
let obj = object_getIvar(object, ivars![i])
if let temp = obj as? UIView {
if nameArray.contains(temp){
let name = String.init(cString: ivar_getName(ivars![i])!)
dict[name] = temp
}
}
}
free(ivars)
return dict
}
//MARK: 懒加载创建label
lazy var lazyLabel: UILabel = self.addLabel_d(title: "");
func addLabel_d(title:String) -> UILabel {
let label = UILabel(frame: CGRect.init(x: 0, y: 0, width: 200, height: 40))
label.center = self.view.center
label.backgroundColor = UIColor.gray
label.textColor = UIColor.white
label.textAlignment = NSTextAlignment.center
label.numberOfLines = 0
label.lineBreakMode = NSLineBreakMode.byWordWrapping
label.text = title
label.font = UIFont.systemFont(ofSize: 17)
return label;
}
//lazy
lazy var datasource:NSArray = {
var tmpdatasource = NSArray(objects: ["title":"dispatch使用","content":["sync -- 同步","async -- 异步","delay -- 延迟执行三秒","main -- 主线程","global -- 全局并发队列"]],["title":"网络请求","content":["GET -- 请求","POST -- 请求","下载图片"]],["title":"自定义组件","content":["toast","。。。"]])
return tmpdatasource
}()