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

问题描述:

我想更改键盘toobar(即提交按钮)的标题颜色,另一种方法是如何为键盘工具栏添加图像。 TIA更改键盘工具栏的标题颜色objective-C

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 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]; 
+0

如何将按钮设置为中心 – Abhimanyu

+0

添加这个 UIBarButtonItem * flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 检查此链接http://*.com/questions/17969260/how-to-show-button-in-center-of-toolbar – nick

尝试下面的代码,并做修改按您的要求:

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];