2017-01-13 6 views
0

Как я могу отобразить значок изображения с правой стороны UIBarButtonItem на панели инструментов?Значок изображения в правой части UIBarButtonItem на панели инструментов (iOS)

let button = UIBarButtonItem(
     image_name: "next_item", 
     title: "Continue", 
     target: self, 
     action_selector: nil 
    ) 

Я пытался манипулировать button.imageInsets, но это ничего не изменило для меня.

Swift 3, iOS 8+.

Я ожидаю, что результат, как это: enter image description here

+0

название: «Продолжить» « – iDeveloper

+0

@iDeveloper nice solution =), но это будет неправильный размер и форма. –

+0

просто используйте custome view и используйте lable для заголовка и изображения для вашего изображения. –

ответ

0

Используйте attributted строку и добавить изображение с Последовательностью и отобразить его на названии

// create an NSMutableAttributedString that we'll append everything to 
let fullString = NSMutableAttributedString(string: "Start of text") 

// create our NSTextAttachment 
let image1Attachment = NSTextAttachment() 
image1Attachment.image = UIImage(named: "Icon.png") 

// wrap the attachment in its own attributed string so we can append it 
let image1String = NSAttributedString(attachment: image1Attachment) 

// add the NSTextAttachment wrapper to our full string, then add some more text. 
fullString.append(image1String) 
fullString.append(NSAttributedString(string: "End of text")) 

// draw the result in a label 
yourLabel.attributedText = fullString 
+0

Вы уверены, что я могу использовать Attibured String с представлением UIBarButtonItem по умолчанию? 'button.title' -' String'. Должен ли я создать пользовательский вид с меткой для этого метода? –

+0

Да, вы можете использовать или попробовать один раз. – nick