无法修改UIBarButtonItem(iOS6)的字体大小

时间:2014-07-13 14:44:31

标签: objective-c ios6 nsdictionary uibarbuttonitem font-size

我正在尝试修改它,执行此操作:

button = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStylePlain target:self action:@selector(test:)];
NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:12.0]};
[button setTitleTextAttributes:attributes forState:UIControlStateNormal];

这不起作用。我该怎么办?谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

尝试将自定义按钮添加到右栏按钮,如下所示..

UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(0, 0, yourWidth, yourHeight);
[backButton.titleLabel setFont:[UIFont fontWithName:@"customFont" size:15.0]];
[backButton.titleLabel.text = @"yourText";
[backButton addTarget:self action:@selector(showPreviousView) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *customBarButton = [[UIBarButtonItem alloc]initWithCustomView:customButton];