UIImagePickerController中的左右barButtons字体

时间:2015-08-23 12:21:41

标签: ios swift uiimagepickercontroller uibarbuttonitem

将自定义字体设置为UIImagePickerController的左右UIBarButtons的方法是什么?

我已经尝试过这段代码,但它不起作用:

let imagePicker = UIImagePickerController()
imagePicker.navigationBar.barTintColor = UIColor(hex: 0x212121)
imagePicker.navigationBar.translucent = false
imagePicker.navigationBar.tintColor = UIColor.whiteColor()
imagePicker.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "Roboto-Regular", size: 20.0)!]

// doesn't work
imagePicker.navigationItem.backBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "Roboto-Regular", size: 25.0)!], forState: UIControlState.Normal)
imagePicker.navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "Roboto-Regular", size: 20.0)!], forState: UIControlState.Normal)
imagePicker.navigationItem.rightBarButtonItem?.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "Roboto-Regular", size: 20.0)!], forState: UIControlState.Normal)

1 个答案:

答案 0 :(得分:0)

您需要创建子类UIImagePickerController并设置自己的工具栏。

苹果有一个很好的例子:https://developer.apple.com/library/ios/samplecode/PhotoPicker/Introduction/Intro.html

这是目标-C但我相信它会让你知道你需要做什么。