美文网首页
UISearchBars设置圆框和背景色

UISearchBars设置圆框和背景色

作者: yeyuCoder | 来源:发表于2019-07-24 15:07 被阅读0次

    UIView *naviView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, TopHeight)];

    naviView.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:naviView];

    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(20, StateHeight+6, ScreenWidth-90, 32)];

    [searchBar setBackgroundImage:[UIImage new]];

    searchBar.backgroundColor = HexColor(@"#F5F7F8", 1);

    searchBar.layer.cornerRadius = 16;

    searchBar.layer.masksToBounds = YES;

    searchBar.placeholder = @"搜索关键字";

    searchBar.delegate = self;

    [naviView addSubview:searchBar];

    UITextField *searchTF = [searchBar valueForKey:@"_searchField"];

    searchTF.tintColor = Color_Main;

    searchTF.textColor = Color_Title;

    searchTF.backgroundColor = [UIColor clearColor];

    searchTF.font = Font(16);

    UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-60, StateHeight, 48, 44)];

    cancelBtn.titleLabel.font = Font(16);

    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];

    [cancelBtn setTitleColor:Color_Main forState:UIControlStateNormal];

    [cancelBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];

    [cancelBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];

    [naviView addSubview:cancelBtn];

    相关文章

      网友评论

          本文标题:UISearchBars设置圆框和背景色

          本文链接:https://www.haomeiwen.com/subject/dnpxrctx.html