【问题标题】:Custom UINavigationBar iOS with UITextView使用 UITextView 自定义 UINavigationBar iOS
【发布时间】:2017-10-05 05:38:00
【问题描述】:
我正在尝试在 iOS 上完成以下任务:
自定义 UINavigationBar iOS 带有两个 UITextView
您可以在 Android 上看到相同的内容。
这可能与 UINavigationBar 吗?
我该怎么做?
我尝试将 UIBarButtonItem 与自定义 UIView 一起使用,但它似乎在大小上受到限制,因此无法完成我想要的。
【问题讨论】:
标签:
ios
uinavigationcontroller
uinavigationbar
【解决方案1】:
类似的东西。故事板不可能,甚至可能不会尝试。
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))
}
}