Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 朴素风格的UINavigationBar巴布托风格_Iphone_Image_Uinavigationbar_Uibarbuttonitem - Fatal编程技术网

Iphone 朴素风格的UINavigationBar巴布托风格

Iphone 朴素风格的UINavigationBar巴布托风格,iphone,image,uinavigationbar,uibarbuttonitem,Iphone,Image,Uinavigationbar,Uibarbuttonitem,我得到了以下代码: - (id)init { if (self = [super init]) { self.title = @"please wait"; UIBarButtonItem *favorite = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"star.png"] style:UIBarButtonItemStylePlain target:self action:@selec

我得到了以下代码:

- (id)init {
  if (self = [super init]) {
      self.title = @"please wait";
      UIBarButtonItem *favorite = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"star.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonFavoriteClicked:)];
      self.navigationItem.rightBarButtonItem = favorite;
  }

  return self;
}
但我的按钮看起来仍然像一个带有UIBarButtonimStyle边框的按钮


有没有办法在这个位置设置一个简单样式的按钮?

虽然Frank是对的,但是这个代码应该在
viewDidLoad
中,这里的问题是BarButtons是什么样子的。如果希望它看起来不同,则需要使用不同类型的UIView。您可以将UIButton添加到UIToolbar

-(void)viewDidLoad {
  [super viewDidLoad];
  self.title = @"please wait";
  self.navigationItem.rightBarButtonItem = [[[UIButton alloc] init] autorelease];
}
编辑:

对不起,你想要一个普通的维吾尔布托人。我不相信你能用UINavigationBar做到这一点。您可以尝试添加一个UserInteractionEnabled UILabel作为RightBarButtonim,我不确定它是否有效

这似乎目前不可能。
.

请尝试以下方法:

- (id)init {
  if (self = [super init]) {
      self.title = @"please wait";

      UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
      [button setImage:[UIImage imageNamed:@"star.png"] forState:UIControlStateNormal];
      [button addTarget:self action:@selector(buttonFavoriteClicked) forControlEvents:UIControlEventTouchUpInside];
      UIBarButtonItem *favorite = [[UIBarButtonItem alloc] initWithCustomView:button];
      [button release];

      self.navigationItem.rightBarButtonItem = favorite;
  }

  return self;
}

希望有帮助。

在interface builder中创建一个UIButton,使其看起来完全符合您的需要。在您的.h中为中创建一个插座:

IBOutlet UIButton * _myButton;
然后使用自定义视图将其设置为右栏按钮项,这将消除边框:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_myButton];

这是因为UIButton是UIView的一个子类。

或者在没有IB的代码中执行此操作:

    UIImage *img = [UIImage imageNamed:@"white_star.png"];

      CGSize itemSize = CGSizeMake(20, 20);
      UIGraphicsBeginImageContext(itemSize);
      CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
      [img drawInRect:imageRect];
      img = UIGraphicsGetImageFromCurrentImageContext();
      UIGraphicsEndImageContext();


  UIBarButtonItem *barButton = [[UIBarButtonItem alloc ] initWithImage:img style:UIBarButtonSystemItemAdd target:self action:@selector(favoriteButtonClicked)];
  barButton.style = UIBarButtonItemStyleBordered;
// add setting button to nav bar
UIImage* settingsGearImg = [UIImage imageNamed:@"settings_gear.png"];
CGRect frameimg = CGRectMake(0, 0, settingsGearImg.size.width, settingsGearImg.size.height);
UIButton *settingsButton = [[UIButton alloc] initWithFrame:frameimg];
[settingsButton setBackgroundImage:settingsGearImg forState:UIControlStateNormal];
[settingsButton addTarget:self action:@selector(settingsButtonAction) forControlEvents:UIControlEventTouchUpInside];
[settingsButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *settingButtonItem =[[UIBarButtonItem alloc] initWithCustomView:settingsButton];
self.navigationItem.leftBarButtonItem = settingButtonItem;
结果:

使用此图标图像时(白色背景上为白色,因此此处不可见-链接为:): 试试这个

UIBarButtonItem *barBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"more.png"] style:UIBarButtonItemStylePlain target:self action:@selector(didPressButton)];

这很奇怪,但很管用。对图片/出口说“不”!您甚至不应该设置uiBarButtonimStyleplain属性。诀窍是将按钮放入具有一些特殊属性的UIToolBar中:

UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:@"Cool plain bar"];
UIToolbar *tools = [[UIToolbar alloc]
                    initWithFrame:CGRectMake(0.0f, 0.0f, 44.0f, 44.01f)];
tools.clipsToBounds = NO;
tools.barStyle = -1; // clear background
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:1];
UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshTableView)];
[buttons addObject:bi];
[tools setItems:buttons animated:NO];
UIBarButtonItem *rightButtons = [[UIBarButtonItem alloc] initWithCustomView:tools];

item.rightBarButtonItem = rightButtons;
item.hidesBackButton = YES;
[myCoolNavigationBar pushNavigationItem:item animated:NO];

为什么不试试UI7Kit呢?对我来说效果很好,易于使用。

另外,RightBarButtonim需要一个UIBarButtonim作为对象类型真的吗?妈的,我知道你可以在标题里写任何你想写的东西。这真令人失望。
@property(非原子,保留)uibarbuttonite*rightbuttonite嗯,还是我解释错了什么?不,你绝对是对的,我只是从来没有注意到,因为我总是使用带边框的按钮。代码包含错误,而不是他想要的
UIBarButtonSystemItemAdd
不是UIBarButtonItemStyle。另外,如果要获得阴影效果,请执行以下操作:
\u myButton.layer.shadowOpacity=1.0
\u myButton.layer.shadowRadius=0.0
\u myButton.layer.shadowColor=[UIColor blackColor].CGColor
\u myButton.layer.shadowOffset=CGSizeMake(0.0,[UIScreen mainScreen]。比例==1?-1:-1.5)我同意这个解决方案。但是,你认为苹果会在他们的iPad邮件应用程序中做到这一点吗?似乎有点小问题。@AjayUI指南说导航栏忽略了项的
样式
属性,因为无边框按钮不适合导航栏。至于邮件,左侧有一个导航栏(带边框的按钮),右侧有一个工具栏(允许使用无边框按钮)。分配完后,您也应该释放
收藏夹