2016-12-29 100 views
-2

我想更改鍵盤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]; 

回答

0

如果你想改變整個應用程序工具欄上的變化,然後使用

[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://stackoverflow.com/questions/17969260/how-to-show-button-in-center-of-toolbar – nick

1

嘗試下面的代碼,並做修改按您的要求:

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