前端之家收集整理的这篇文章主要介绍了
Swift自定义Tool,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
//设置tool private func prepareToolBar(){ let toolBar = UIToolbar() view.addSubview(toolBar) let w = UIScreen.mainScreen().bounds.size.width toolBar.ff_AlignInner(type: ff_AlignType.BottomLeft,referView: view,size: CGSize(width: w,height: 44)) let items = [["imageName": "compose_toolbar_picture"],["imageName": "compose_mentionbutton_background"],["imageName": "compose_trendbutton_background"],["imageName": "compose_emoticonbutton_background"],["imageName": "compose_addbutton_background"]] //初始化一个按钮的数组 var btnItems = [UIBarButtonItem]() for dict in items{ btnItems.append(UIBarButtonItem(customView: UIButton(imageName: dict["imageName"]!))) btnItems.append(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace,target: nil,action: nil)) } //移除最后一个拉伸弹簧 btnItems.removeLast() toolBar.items = btnItems } //配合
分类 extension UIButton{ /// 便利构造
函数 /// /// - parameter imageName: 图像
名称 /// /// - returns: UIButton convenience init(imageName: String){ self.init() setImage(UIImage(named: imageName),forState: UIControlState.Normal) setImage(UIImage(named: imageName + "_highlighted"),forState: UIControlState.Highlighted) sizeToFit() } }