工具栏(iOS)上UIBarButtonItem右侧的图像图标

时间:2017-01-13 07:14:49

标签: ios swift uibarbuttonitem uitoolbar

如何在工具栏上的UIBarButtonItem右侧显示图像图标?

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

我试图操纵button.imageInsets,但它对我没有任何改变。

Swift 3,iOS 8 +。

我希望结果如下: enter image description here

2 个答案:

答案 0 :(得分:1)

您可以使用自定义视图初始化UIBarButton。

https://developer.apple.com/reference/uikit/uibarbuttonitem/1617151-init

在自定义视图中,将UILabel放在旁边,然后放置UIImageView

答案 1 :(得分:0)

使用属性字符串并使用String添加图像并将其显示在标题

     <?xml version="1.0" encoding="UTF-8"?>
        <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
          <persistence-unit name="Web2PU" transaction-type="RESOURCE_LOCAL">
            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
            <class>project.entities.Products</class>
            <exclude-unlisted-classes>false</exclude-unlisted-classes>
            <properties>
              <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/Cart"/>
              <property name="javax.persistence.jdbc.user" value="root"/>
              <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
              <property name="javax.persistence.jdbc.password" value=""/>
            </properties>
          </persistence-unit>
        </persistence>