我做了一个自定义UIBarButtonItem从一个UIButton.自定义栏按钮可见,动作正常,大小正确,可以看到背景颜色; 但是无法看到手动设置的标题.也许背景是在文本上?我不确定,帮忙吗?
在viewDidLoad:
UIButton *resetButton = [UIButton buttonWithType:UIButtonTypeCustom];
resetButton.frame = CGRectMake(0, 0, 65, 30);
[resetButton addTarget:self action:@selector(speakPhrase:) forControlEvents:UIControlEventTouchUpInside];
resetButton.titleLabel.font = [UIFont fontWithName:@"ProximaNova-Bold" size:19];
resetButton.titleLabel.text = @"RESET";
resetButton.titleLabel.textColor = [UIColor whiteColor];
resetButton.backgroundColor = [UIColor redColor];
resetButton.showsTouchWhenHighlighted = YES;
UIBarButtonItem *resetBarBTN = [[UIBarButtonItem alloc] initWithCustomView:resetButton];
self.navigationItem.rightBarButtonItem = resetBarBTN;
Run Code Online (Sandbox Code Playgroud)