Ios 更改键盘工具栏objective-C的标题颜色

Ios 更改键盘工具栏objective-C的标题颜色,ios,objective-c,iphone,xcode,uibarbuttonitem,Ios,Objective C,Iphone,Xcode,Uibarbuttonitem,我想更改键盘toobar的标题颜色,即(提交按钮),另一个问题是如何为键盘工具栏添加图像。短暂性脑缺血发作 UIToolbar *keyboardToolbar = [[UIToolbar alloc] init]; [keyboardToolbar sizeToFit]; keyboardToolbar.translucent=NO; //if you want it. keyboardToolbar.barTintColor = [UIColor lightGrayColor]; _

我想更改键盘
toobar
的标题颜色,即(提交按钮),另一个问题是如何为键盘工具栏添加图像。短暂性脑缺血发作

UIToolbar *keyboardToolbar = [[UIToolbar alloc] init];

[keyboardToolbar sizeToFit];

keyboardToolbar.translucent=NO; //if you want it.

keyboardToolbar.barTintColor = [UIColor lightGrayColor];

_txtCommentView.inputAccessoryView = keyboardToolbar;

keyboardToolbar.items = [NSArray arrayWithObjects:
                             [[UIBarButtonItem alloc]initWithTitle:@"Submit" style:UIBarButtonItemStyleBordered target:self action:@selector(submitClicked:)],
                              nil];

尝试以下代码并根据您的要求进行更改:

UIToolbar *keyboardToolbar = [[UIToolbar alloc] init];

[keyboardToolbar sizeToFit];

keyboardToolbar.translucent=NO; //if you want it.

keyboardToolbar.barTintColor = [UIColor lightGrayColor];

_txtCommentView.inputAccessoryView = keyboardToolbar;


UIBarButtonItem *submit = [[UIBarButtonItem alloc] initWithTitle:@"Submit"
                                                              style:UIBarButtonItemStyleBordered
                                                             target:self action:@selector(submitClicked:)];

//Change submit button attributes here as you want
[submit setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIFont fontWithName:@"Helvetica-Bold" size:18.0], NSFontAttributeName,
                                   [UIColor whiteColor], NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateNormal];

keyboardToolbar.items = [NSArray arrayWithObjects:submit, nil];

如果要更改整个应用程序工具栏中的更改,请使用

[UIToolbar appearance].tintColor = [UIColor redColor];
[UIToolbar appearance].barTintColor = [UIColor greenColor];
您还可以使用以下代码进行更改:

 NSDictionary *attributes = @{
                                 NSForegroundColorAttributeName: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0],

                                 NSFontAttributeName: [UIFont fontWithName:@"Arial" size:16.0]
                                 };
    [[UIBarButtonItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];

如何将按钮设置为中心添加此UIBarButtonItem*flexibleSpace=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemFlexibleSpace目标:nil操作:nil];检查此链接