UIBarButtonItem问题

时间:2015-05-16 13:04:23

标签: ios swift uibarbuttonitem

我的UIBarButton有问题,按钮的颜色与原始图像不同。

     < script >
      jQuery(document).ready(function($) {
        $('.lightbox').click(function(e) {
          //prevent default action (hyperlink)
          e.preventDefault();

          //Get clicked link href
          var image_href = $(this).attr("href");

          /* 	
		If the lightbox window HTML already exists in document, 
		change the img src to to match the href of whatever link was clicked
		
		If the lightbox window HTML doesn't exists, create it and insert it.
		(This will only happen the first time around)
		*/

          if ($('#lightbox').length) { // #lightbox exists
            //place href as img src value
            $('#content').html('<img src="' + image_href + '" />');
            //show lightbox window - you could use .show('fast') for a transition
            $('#lightbox').show('slow');
          } else { //#lightbox does not exist - create and insert (runs 1st time only)

            //create HTML markup for lightbox window
            var lightbox =
              '<div id="lightbox">' +
              '<p>Click to close</p>' +
              '<div id="content">' + //insert clicked link's href into img src
              '<img src="' + image_href + '" />' +
              '</div>' +
              '</div>';

            //insert lightbox HTML into page
            $('#stage').append(lightbox)
            $('.work').slideUp('slow');
          }

        });


        if ($('#lightbox')) {
          //Click anywhere on the page to get rid of lightbox window
          $('body').on('click', function() {
            $('#lightbox').remove();
            $('.work').slideDown('slow');
          });
        }
      }); < /script>

按钮的颜色是蓝色,但我的图像是黄色的!

像这样:enter image description here

如果你可以帮助我,那真是棒极了:)

3 个答案:

答案 0 :(得分:2)

尝试此代码:

var image : UIImage? = UIImage(named:"settings.png").imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)

答案 1 :(得分:2)

设置图片UIImageRenderingMode属性:

 self.navigationItem.rightBarButtonItem =  UIBarButtonItem(image: UIImage(named: "settings.png").imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), style: .Plain, target: self, action: "didTapSettingButton")

答案 2 :(得分:0)

试试这样。

在班级var settingRightBarButton : UIBarButtonItem?

中创建一个栏按钮属性

然后

let shareBarButtonImage = UIImage(named: "settings")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
self.settingRightBarButton = UIBarButtonItem(image: shareBarButtonImage, style: UIBarButtonItemStyle.Plain, target: self, action: Selector("didTapSettingButton"))
self.navigationItem.rightBarButtonItem = self.settingRightBarButton

Images.xcassets

中添加图片