UINavigationBar BarButtonItem with Plain Style

前端 未结 8 2226
不思量自难忘°
不思量自难忘° 2020-12-14 09:19

i got the following code:

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


        
8条回答
  •  忘掉有多难
    2020-12-14 09:27

    Try this instead:

    - (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;
    }
    

    Hope it helps.

提交回复
热议问题