标签:cto tin idt control 点击 lang 控制器 自定义 监听
/// 图片数组
private lazy var imageNames : [String] = {
return ["tabbar_home", "tabbar_message_center", "" ,"tabbar_discover", "tabbar_profile"]
}()
private func adjustItems() {
for i in 0..<tabBar.items!.count {
// 1.取出item
let item = tabBar.items![i]
// 2.如果是第二个item,则不可以和用户交互.并且不需要设置图片
if i == 2 {
item.enabled = false
continue
}
// 2.设置图片
item.image = UIImage(named: imageNames[i])
item.selectedImage = UIImage(named: imageNames[i] + "_highlighted")
}
}
convenience init(imageName : String, bgImageName : String) {
self.init()
// 设置相关属性
setBackgroundImage(UIImage(named: bgImageName), forState: .Normal)
setBackgroundImage(UIImage(named: bgImageName + "_highlighted"), forState: .Highlighted)
setImage(UIImage(named: imageName), forState: .Normal)
setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
sizeToFit()
}
/// 发布微博按钮
private lazy var composeBtn : UIButton = {
// let btn = UIButton.createButton("tabbar_compose_icon_add", bgImageName: "tabbar_compose_button")
let btn = UIButton(imageName: "tabbar_compose_icon_add", bgImageName: "tabbar_compose_button")
btn.center = CGPoint(x: self.tabBar.bounds.width * 0.5, y: self.tabBar.bounds.height * 0.5)
// 监听按钮的点击
// Selector("composeBtnClick")
// "composeBtnClick"
btn.addTarget(self, action: Selector("composeBtnClick"), forControlEvents: .TouchUpInside)
return btn
}()
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// 1.调整items
adjustItems()
// 2.添加`加号`按钮
tabBar.addSubview(composeBtn)
}
标签:cto tin idt control 点击 lang 控制器 自定义 监听
原文地址:http://www.cnblogs.com/xufengyuan/p/7414152.html