ASAppBar
截图
导入语句
import ASAppBar
出囗初始化
@IBOutlet weak var appBar: ASAppBarClassic!
变量
static let boxPadding = CGSize(width: 10, height: 0)
static var barTitleProps: ASAProps {ASAProps(ASAMultiplier(5.0, 0.6), CGSize(width: 5, height: 5))}
static var barSearchProps: ASAProps {ASAProps(ASAMultiplier(0.6, 0.6), CGSize(width: 5, height: 0))}
static var barProps: ASAProps {ASAProps(ASAMultiplier(0.6, 0.6), CGSize(width: 5, height: 5))}
let title = ASAChangableView("App Name", {self.initTitleLabel("App Name 1")}, {self.initTitleLabel("App Name 2")}, ViewController.barTitleProps, ViewController.barTitleProps)
let menu = ASAChangableView("Menu", {UIImageView(image: UIImage(named: "menu"))}, {UIImageView(image: UIImage(named: "menu"))}, ViewController.barProps, ViewController.barProps)
let more = ASAChangableView("More", {UIImageView(image: UIImage(named: "moreIcon"))}, {UIImageView(image: UIImage(named: "moreIcon"))}, ViewController.barProps, ViewController.barProps)
let notifi = ASAChangableView("Notification", {UIImageView(image: UIImage(named: "notification"))},{UIImageView(image: UIImage(named: "notification"))}, ViewController.barProps, ViewController.barProps)
let search = ASAChangableView("Search", {UIImageView(image: UIImage(named: "search"))}, {self.initSearchBar()}, ViewController.barProps, ViewController.barSearchProps)
let showMoreProps = ASADropDownProp(UIFont.systemFont(ofSize: 15), UIColor.black, UIColor.lightGray, UIColor.lightGray)
设置背景颜色及框内填充
self.appBar
.setBackgroundColor(UIColor.blue)
.setBoxPadding(ViewController.boxPadding)
设置左侧菜单视图
self.appBar
.setSideView("0", menu, true, false, false, .left, { (appbar, subView, isOn) in print("\(isOn)") })
设置左侧标题视图
self.appBar
.setSideView("1", title, true, false, false, .left, { (appbar, subView, isOn) in print("\(isOn)")})
设置右侧可扩展视图及其事件通过ID改变其他大小
self.appBar
.setSideView("4", search, true, false, true, .right, { (appbar, subView, isOn) in print("\(isOn)"); appbar.setMultiplier("1", (isOn ? ASAMultiplier.zero : ViewController.barTitleProps.multiplier)) })
完整代码切片
import UIKit
import ASAppBar
class ViewController: UIViewController {
@IBOutlet weak var appBar: ASAppBarClassic!
static let boxPadding = CGSize(width: 10, height: 0)
static var barTitleProps: ASAProps {ASAProps(ASAMultiplier(5.0, 0.6), CGSize(width: 5, height: 5))}
static var barSearchProps: ASAProps {ASAProps(ASAMultiplier(0.6, 0.6), CGSize(width: 5, height: 0))}
static var barProps: ASAProps {ASAProps(ASAMultiplier(0.6, 0.6), CGSize(width: 5, height: 5))}
override func viewDidLoad() {
super.viewDidLoad()
let title = ASAChangableView("App Name", {self.initTitleLabel("App Name 1")}, {self.initTitleLabel("App Name 2")}, ViewController.barTitleProps, ViewController.barTitleProps)
let menu = ASAChangableView("Menu", {UIImageView(image: UIImage(named: "menu"))}, {UIImageView(image: UIImage(named: "menu"))}, ViewController.barProps, ViewController.barProps)
let more = ASAChangableView("More", {UIImageView(image: UIImage(named: "moreIcon"))}, {UIImageView(image: UIImage(named: "moreIcon"))}, ViewController.barProps, ViewController.barProps)
let notifi = ASAChangableView("Notification", {UIImageView(image: UIImage(named: "notification"))},{UIImageView(image: UIImage(named: "notification"))}, ViewController.barProps, ViewController.barProps)
let search = ASAChangableView("Search", {UIImageView(image: UIImage(named: "search"))}, {self.initSearchBar()}, ViewController.barProps, ViewController.barSearchProps)
let showMoreProps = ASADropDownProp(UIFont.systemFont(ofSize: 15), UIColor.black, UIColor.lightGray, UIColor.lightGray)
self.appBar
.setBackgroundColorAll(UIColor.blue)
.setBoxPadding(ViewController.boxPadding)
.setSideView("0", menu, true, false, false, .left, { (appbar, subView, isOn) in print("\(isOn)") })
.setSideView("1", title, true, false, false, .left, { (appbar, subView, isOn) in print("\(isOn)")})
.setSideView("2", more, true, false, false, .right, { (appbar, subView, isOn) in appbar.showMore(subView, showMoreProps.background, showMoreProps, {(index, title) in print("title: \(title)")}); print("\(isOn)")})
.setSideView("3", notifi, true, false, false, .right, { (appbar, subView, isOn) in print("\(isOn)")})
.setSideView("4", search, true, false, true, .right, { (appbar, subView, isOn) in print("\(isOn)"); appbar.setMultiplier("1", (isOn ? ASAMultiplier.zero : ViewController.barTitleProps.multiplier)) })
.setSideView("5", notifi, false, false, false, .right, { (appbar, subView, isOn) in print("\(isOn)")})
.setSideView("6", more, false, false, false, .right, { (appbar, subView, isOn) in print("\(isOn)")})
}
func initTitleLabel(_ text: String? = nil) -> UILabel {
let label = UILabel()
label.text = text ?? ""
label.font = UIFont.systemFont(ofSize: 12)
label.textColor = .white
return label
}
func initSearchBar() -> UISearchBar {
let searchBar = UISearchBar()
searchBar.searchBarStyle = UISearchBar.Style.prominent
searchBar.placeholder = "Search..."
searchBar.sizeToFit()
searchBar.backgroundImage = UIImage()
searchBar.delegate = self
searchBar.tintColor = UIColor.clear
searchBar.backgroundColor = UIColor.clear
searchBar.barStyle = .blackTranslucent
if let textfield = searchBar.value(forKey: "searchField") as? UITextField {
textfield.textColor = UIColor.white
textfield.backgroundColor = UIColor.clear
textfield.font = UIFont.systemFont(ofSize: 12)
}
return searchBar
}
}
extension ViewController: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, textDidChange textSearched: String) {
print("textSearched: \(textSearched)")
}
}
要运行示例项目,首先克隆存储库,然后从示例目录运行pod install
。
要求
安装
ASAppBar通过CocoaPods可用。要安装它,只需将以下行添加到您的Podfile中:
pod 'ASAppBar'
作者
[email protected], [email protected]
许可
ASAppBar遵循MIT许可证。有关更多信息,请参阅LICENSE文件。