我正在尝试在iOS上完成以下操作: 使用两个UITextView自定义UINavigationBar iOS
Bellow你可以在Android上看到相同的内容。
UINavigationBar可以实现吗? 我怎么能这样做?
我尝试将UIBarButtonItem与自定义UIView一起使用,但似乎它的大小有限,因此无法实现我的目标。
答案 0 :(得分:0)
像这样的东西。用故事板赢得它是不可能的,甚至可能不会尝试。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let layout = UICollectionViewFlowLayout()
UINavigationBar.appearance().barTintColor = UIColor.yellow
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
application.statusBarStyle = .lightContent
let textViewOne = UITextView()
textViewOne.text = "1000"
window?.addSubview(textViewOne)
//top constraint
window?.addConstraintsWithFormat("H:[v0(100)]-16-|", views: textViewOne)
window?.addConstraintsWithFormat("V:|-16-[v0(24)]", views: textViewOne)
return true
}
extension UIView {
func addConstraintsWithFormat(_ format: String, views: UIView...) {
var viewsDictionary = [String: UIView]()
for (index, view) in views.enumerated() {
let key = "v\(index)"
view.translatesAutoresizingMaskIntoConstraints = false
viewsDictionary[key] = view
}
addConstraints(NSLayoutConstraint.constraints(withVisualFormat: format, options: NSLayoutFormatOptions(), metrics: nil, views: viewsDictionary))
}
}