我正在尝试从 Apple 新音乐应用程序中的"new"选项卡创建外观:
起初,我认为箭头只是一个 unicode 字符,但我找到的最接近的符号是: ﹀,并且它不是垂直对齐的,因此此代码生成以下内容
navigationItem.title = "All Genres﹀"
navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.redColor()]
您对我如何去做这件事有什么建议吗?
最佳答案
我使用@rounak的解决方案让它工作。这是任何想知道的人的代码
let arrow = UIImage(named: "titleArrow")!.imageWithRenderingMode(.AlwaysOriginal)
let titleButton = UIButton(type: .System)
titleButton.addTarget(self, action: "pickGenre", forControlEvents: .TouchUpInside)
titleButton.setTitle("All Genres", forState: .Normal)
titleButton.setTitleColor(UIColor.redColor(), forState: .Normal)
titleButton.titleLabel!.font = UIFont.systemFontOfSize(16)
titleButton.setImage(arrow, forState: .Normal)
titleButton.sizeToFit()
titleButton.titleEdgeInsets = UIEdgeInsetsMake(0, -titleButton.imageView!.frame.width, 0, titleButton.imageView!.frame.width)
titleButton.imageEdgeInsets = UIEdgeInsetsMake(0, titleButton.titleLabel!.frame.width + 2.5, 0, -titleButton.titleLabel!.frame.width)
navigationItem.titleView = titleButton
关于swift - 重新创建 Apple Music UINavigationController 标题箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31193209/