2015-12-29 149 views
1

有很多关于如何在UISearchbar中访问UITextField的Objective-C变体,因此您可以比暴露的SearchBar方法更具体地设计它的样式,即我们想要更改 -设置Xamarin UISearchBar UITextField字体大小/颜色+背景

  • 字体类型/大小
  • 字体颜色
  • 文本字段背景的颜色,以便搜索栏是一种颜色

认为这将是很高兴看到Xamar在溶液(个),这是一定的OBJ-C技术似乎并没有(我可能只是缺少代码)翻译 -

例如,在 -

Change the font size and font style of UISearchBar iOS 7

- (void)viewDidLoad 
{ 

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setDefaultTextAttributes:@{ 
     NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:20], 
    }]; 

} 

外貌像一个胜利者,但性质不是“看似”暴露不知道能翻译这Xamarin -

UITextField.AppearanceWhenContainedIn(typeof (UISearchBar))).HowToSetFont ... 

我会首发回答一个我刚才碰到过,BU没有兴趣了解其他用户如何解决样式搜索栏的问题。

回答

3
_filterSearchBar = new UISearchBar 
{ 
    BarTintColor = UIColor.Red,  // We want a red search bar with text field background same as outer "margin" 
    TintColor = UIColor.White, 
    SearchBarStyle = UISearchBarStyle.Default, 
    BackgroundImage = UIImage.FromFile("transparent1x1.png")  // "trick" to ensure background is clean 
}; 

// Main Part - Use KVO to access text field 
var uiTextField = (UITextField)_filterSearchBar.ValueForKey(new NSString("_searchField")); 

uiTextField.Font = YourFontHere; 
uiTextField.TextColor = UIColor.White; 
uiTextField.BackgroundColor = UIColor.Red;    

// Placeholder colour is white 
uiTextField.AttributedPlaceholder = new NSAttributedString("SearchBarPlaceholder", null, UIColor.White); 

// We still have not sorted spyglass icon colour et al to white but can try set icon image later