[英]Custom UINavigationBar iOS with UITextView
I am trying to accomplish the following on iOS: Custom UINavigationBar iOS with two UITextView 我正在尝试在iOS上完成以下任务:具有两个UITextView的自定义UINavigationBar iOS
Bellow you can see the same on Android. 在下面,您可以在Android上看到相同的内容。
Is this possible with UINavigationBar ? UINavigationBar是否可能? How can I do this ?
我怎样才能做到这一点 ?
I tried using a UIBarButtonItem with a custom UIView but it seems that is limited on the size so couldn't accomplish what I want. 我尝试将UIBarButtonItem与自定义UIView一起使用,但似乎在大小上受到限制,因此无法完成我想要的操作。
Something like this. 这样的事情。 It won't be possible with storyboards and probably wouldn't even try.
情节提要将无法实现,甚至可能不会尝试。
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))
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.