Swift自定义Tool

前端之家收集整理的这篇文章主要介绍了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() } } 原文链接:https://www.f2er.com/swift/325689.html

猜你在找的Swift相关文章