我想将具有不同字体大小的属性字符串设置为导航项的属性标题,导航项是导航栏的一部分,属性prefersLargeTitles设置为true。
我尝试将自定义视图分配给导航项的属性viewTitle,但是视图的高度总是限制在44 px,这是导航条高度的一半,并有一个大标题。
是否可以添加一个自定义viewTitle,其高度与导航条的高度相等?
self.navigationController?.navigationBar.prefersLargeTitles = true
let attrString = NSMutableAttributedString(string: "Page 1",
attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 30)]);
attrString.append(NSMutableAttributedString(string: " Chapter 3",
attributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 19)]));
let label = UILabel(frame: CGRect.zero)
label.attributedText = attrString
let frame = CGRect(origin: CGPoint.zero, size: CGSize(width: 256, height: 88))
let titleView = UIView(frame:CGRect.zero)
titleView.addSubview(label)
label.frame = frame
self.navigationItem.titleView = titleView
self.navigationItem.titleView?.frame = frame

发布于 2018-10-18 18:55:25
除非您破解视图层次结构,否则就不能使用公共api来实现它。
https://stackoverflow.com/questions/52873263
复制相似问题