【问题标题】:How Can I Set UISearchBar to Black Translucent Via Code?如何通过代码将 UISearchBar 设置为黑色半透明?
【发布时间】:2011-09-07 00:06:51
【问题描述】:

我知道如何使用 IB 来做到这一点,但我如何只用代码来做到这一点?还是我必须手动进行 RGB?

我有:

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

【问题讨论】:

    标签: iphone objective-c cocoa-touch ipad uisearchbar


    【解决方案1】:

    需要同时使用 barStyle 属性和 translucent 属性:

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

    【讨论】:

      【解决方案2】:

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

      searchBar.barStyle = UIBarStyleBlackTranslucent;

      酷玩得开心:)

      【讨论】:

        【解决方案3】:

        您应该可以通过 UISearchBar 中的两个属性来执行此操作;

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

        tintColor 设置为黑色,并将translucent 设置为YES。

        查看参考以获取更多信息: http://developer.apple.com/library/iOS/#documentation/UIKit/Reference/UISearchBar_Class/Reference/Reference.html

        希望这能解决问题!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-06-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-11-15
          • 2020-07-21
          • 2012-02-22
          相关资源
          最近更新 更多