【问题标题】:Can i have 2 colours in my navigation bar Tittle?我的导航栏标题中可以有 2 种颜色吗?
【发布时间】:2016-05-18 02:54:42
【问题描述】:

我想在导航栏标题中设置 2 种颜色。 如果我不能这样做,我怎样才能将图像完美地居中作为导航栏的标题?

我试过了:

let logo = UIImage(named: "LogoMV_BAR@2x");
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
imageView.image = logo
imageView.contentMode = UIViewContentMode.ScaleAspectFit
self.navigationItem.titleView = imageView

而且它看起来很小而且没有居中。

谢谢大家!

【问题讨论】:

标签: swift colors nsattributedstring navigationbar titlebar


【解决方案1】:

感谢用户 Larme,您的回答对我帮助很大。我就是这样做的:

let A = NSMutableAttributedString(string: "Label Test", attributes: [NSFontAttributeName: UIFont(name: "Georgia", size: 18)!])

A.addAttribute(NSForegroundColorAttributeName, value: UIColor.blueColor(), range: NSRange(location: 6, length: 5))

let LabelTexto: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 30))

LabelText.attributedText = A

self.navigationItem.titleView = LabelText

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-05
    • 1970-01-01
    • 2011-10-22
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-10
    相关资源
    最近更新 更多