我想使用具有一些图像的自定义barbutton。
我正在做下面的代码。但是barbutton没有显示。
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(nowPlayingButtonClicked) forControlEvents:UIControlEventTouchUpInside];
nowPlaying = [[UIBarButtonItem alloc] initWithCustomView:button];
nowPlaying.action = @selector(nowPlayingButtonClicked);
nowPlaying.target = self;
self.navigationItem.rightBarButtonItem = nowPlaying;
最佳答案
您必须为添加到BarButton的Button设置框架
button.frame = CGRectMake(0, 0, 50, 30);