iOS 改动toolbar里面文字的字体和大小

使用NSDictionaty来设置文本的属性:

NSDictionary * attributes = @{NSFontAttributeName: [UIFont fontWithName:@"Heiti SC" size:20]};
    [confirmBarButton setTitleTextAttributes:attributes forState:UIControlStateNormal];

完整代码:

    self.inputToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    self.inputToolbar.translucent = NO;
    self.inputToolbar.barTintColor= [UIColor colorWithRed:26.0/255.0 green:194.0/255.0 blue:97.0/255.0 alpha:1];
    self.inputToolbar.tintColor = [UIColor whiteColor];
    
    UIBarButtonItem *confirmBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Confirm" style:UIBarButtonItemStylePlain target:self action:@selector(doneKeyboard)];
    NSDictionary * attributes = @{NSFontAttributeName: [UIFont fontWithName:@"Heiti SC" size:20]};
    [confirmBarButton setTitleTextAttributes:attributes forState:UIControlStateNormal];
    
    UIBarButtonItem *spaceBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:@selector(doneKeyboard)];
    
    self.inputToolbar.items = [NSArray arrayWithObjects: spaceBarButton, confirmBarButton, spaceBarButton, nil];
    self.textView.inputAccessoryView = self.inputToolbar;

參考链接:http://stackoverflow.com/questions/2720733/how-do-you-set-the-font-size-on-a-uibarbuttonitem

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。