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

Iphone 如何通过代码将UISearchBar设置为黑色半透明?,iphone,objective-c,cocoa-touch,ipad,uisearchbar,Iphone,Objective C,Cocoa Touch,Ipad,Uisearchbar,我知道如何使用IB实现这一点,但如何仅使用代码实现这一点?还是我必须手动执行RGB 我有: UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)]; 您应该能够通过UISearchBar中的两个属性来实现这一点 @property(nonatomic, retain) UIColor *tintColor @property(nonatomic, assign

我知道如何使用IB实现这一点,但如何仅使用代码实现这一点?还是我必须手动执行RGB

我有:

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

您应该能够通过UISearchBar中的两个属性来实现这一点

@property(nonatomic, retain) UIColor *tintColor
@property(nonatomic, assign, getter=isTranslucent) BOOL translucent
tintColor
设置为黑色,并将
半透明设置为YES

有关更多信息,请查看参考资料:


希望这能奏效

您需要同时使用barStyle属性和半透明属性:

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

我相信你可以做到以下几点:

searchBar.barStyle=uibarstyleblacktransparent

祝你玩得开心:)