简体   繁体   English

如何通过代码将UISearchBar设置为黑色半透明?

[英]How Can I Set UISearchBar to Black Translucent Via Code?

I know how to do this using IB, but how can I do this with just code? 我知道如何使用IB做到这一点,但是如何仅用代码就可以做到这一点? OR do I manually have to do the RGB? 还是我必须手动执行RGB?

I have: 我有:

UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];

You need to use the barStyle property and translucent properties together: 您需要同时使用barStyle属性和半透明属性:

UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
searchBar.barStyle = UIBarStyleBlack;
searchBar.translucent = YES;

I believe you can just do the following: 我相信您可以执行以下操作:

searchBar.barStyle = UIBarStyleBlackTranslucent;

Kool have fun :) 库尔玩得开心:)

You should be able to do this via two properties in UISearchBar; 您应该能够通过UISearchBar中的两个属性来执行此操作;

@property(nonatomic, retain) UIColor *tintColor
@property(nonatomic, assign, getter=isTranslucent) BOOL translucent

Set the tintColor to black, and set translucent to YES. tintColor设置为黑色,并将translucent设置为YES。

Check the reference for more info: http://developer.apple.com/library/iOS/#documentation/UIKit/Reference/UISearchBar_Class/Reference/Reference.html 检查参考以获取更多信息: http : //developer.apple.com/library/iOS/#documentation/UIKit/Reference/UISearchBar_Class/Reference/Reference.html

Hope this does the trick! 希望这可以解决问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM