zoukankan      html  css  js  c++  java
  • iOS 设置自带UISearchBar的背景颜色(并改为圆角)

    /** 取消searchBar背景色 */

    - (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size

    {

        CGRect rect = CGRectMake(0, 0, size.width, size.height);

        UIGraphicsBeginImageContext(rect.size);

        CGContextRef context = UIGraphicsGetCurrentContext();

        

        CGContextSetFillColorWithColor(context, [color CGColor]);

        CGContextFillRect(context, rect);

        

        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

          return image;

    }

    然后在viewdidload里面

    /** 设置背景图片 */

        [_searchBar setBackgroundImage:[UIImage imageNamed:@"red_nav_bar"]];   //这里图片的颜色和导航栏一样

    /** 设置背景色 */

       [_searchBar setBackgroundColor:[UIColor redColor]];

    /** 设置文本框背景 * 

    [_searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"imageView"] forState:UIControlStateNormal];

        //更改search圆角

            UITextField *searchField = [self.searchBar valueForKey:@"searchField"];

            if (searchField) {

                [searchField setBackgroundColor:[UIColor whiteColor]];

                searchField.layer.cornerRadius = 14.0f;

                searchField.layer.borderColor = [UIColor colorWithRed:247/255.0 green:75/255.0 blue:31/255.0 alpha:1].CGColor;

                searchField.layer.borderWidth = 1;

                searchField.layer.masksToBounds = YES;

            }

     
  • 相关阅读:
    suseoj 1211: 子集和问题 (dfs)
    suseoj 1210: 会场安排问题 (贪心)
    suseoj 1209: 独立任务最优调度问题(动态规划)
    四级词汇(二)
    四级单词(一)
    nyoj 84-阶乘的0 (规律题)
    nyoj 83-迷宫寻宝(二) (计算几何, 叉积)
    nyoj 82-迷宫寻宝(一) (多重BFS)
    nyoj 79-拦截导弹 (动态规划)
    nyoj 78-圈水池 (凸包)
  • 原文地址:https://www.cnblogs.com/-ios/p/5948643.html
Copyright © 2011-2022 走看看