swift - 重新创建 Apple Music UINavigationController 标题箭头

标签 swift uinavigationcontroller

我正在尝试从 Apple 新音乐应用程序中的"new"选项卡创建外观:

enter image description here

起初,我认为箭头只是一个 unicode 字符,但我找到的最接近的符号是: ﹀,并且它不是垂直对齐的,因此此代码生成以下内容

navigationItem.title = "All Genres﹀"
navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.redColor()]

enter image description here

您对我如何去做这件事有什么建议吗?

最佳答案

我使用@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

[email protected] : enter image description here

关于swift - 重新创建 Apple Music UINavigationController 标题箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31193209/

相关文章:

ios - 阴影在 "sibling" View 顶部不可见

ios - 如何从嵌套 JSON Swift 检索值

ios - 错误 : unrecognized selector sent to instance - Using Camera with OverlayView

ios - 暂时移动 UINavigationView - Facebook 风格

iphone - 如何在一次操作中从 UINavigationController 中弹出一个 View 并将其替换为另一个 View ?

ios - 从导航堆栈中删除 viewController 时出现问题

ios - 尝试设置自定义 backBarButtonItem 图像/难以调整大小的图像

swift - 有没有更简洁的方法来编写这个 if/else 脚本?

ios - 在 UINavigationController 层次结构中共享公共(public)背景图像?

ios - Xcode 旧版本不显示 'Alamofire' 及其在自动完成中的方法