ios navigationItem.titleView

2,581 阅读1分钟

自定义titleView titleView上的控件点击无反应或者适配出现问题 解决办法: 在自定义的titleView中重写intrinsicContentSize的Get方法

  • (CGSize)intrinsicContentSize{

return UILayoutFittingExpandedSize;

} 在自定义的titleView上设置title,用Masonry做布局的时候不要用centerx,centerY,会影响其他控件的布局 iOS11,中,titleView不再放到NavigationBar上,而是放到了UINavigationBarContentView上

关于iOS13 设置导航栏背景色 if (iOS 13.0, *) { self.navigationController?.navigationBar.standardAppearance.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.rgbColor(rgbValue: 0x000000), NSAttributedString.Key.font: UIFont.systemFont(ofSize: 34)] self.navigationController?.navigationBar.standardAppearance.backgroundColor = UIColor.yellow } else { self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.rgbColor(rgbValue: 0x000000), NSAttributedString.Key.font: UIFont.systemFont(ofSize: 34)] self.navigationController?.navigationBar.barTintColor = UIColor.red }

//设置导航栏背景色 self.navigationController.navigationBar.barTintColor = [UIColor whiteColor]; //设置导航栏背景图片 [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"xx.png"] forBarMetrics:UIBarMetricsDefault]; //设置导航栏不透明 self.navigationController.navigationBar.translucent = NO; //设置导航栏透明 [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setShadowImage:[UIImage new]];//去掉黑线 //修改字体颜色和大小 self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17]};