UISearchBar背景色全套解决方案

os系统升级到7.1后,原来在7.0下显示正常的UISearchbar现在又出现问题了。究其原因,是由于UISearchbar的subview又做修改了。

float version = [[[ UIDevice currentDevice ] systemVersion ] floatValue ];

    if ([ mySearchBar respondsToSelector : @selector (barTintColor)]) {

        float  iosversion7_1 = 7.1 ;

        if (version >= iosversion7_1)

        {

            //iOS7.1

            [[[[ mySearchBar . subviews objectAtIndex : 0 ] subviews ] objectAtIndex : 0 ] removeFromSuperview ];

            [ mySearchBar setBackgroundColor :[ UIColor clearColor ]];

        }

        else

        {

            //iOS7.0

            [ mySearchBar setBarTintColor :[ UIColor clearColor ]];

            [ mySearchBar setBackgroundColor :[ UIColor clearColor ]];

        }

    }

    else

    {

        //iOS7.0 以下

        [[ mySearchBar . subviews objectAtIndex : 0 ] removeFromSuperview ];

        [ mySearchBar setBackgroundColor :[ UIColor clearColor ]];

    }

猜你喜欢

转载自lizhuang.iteye.com/blog/2054377
今日推荐