How to add a 1 pixel gray border around a UISearchBar TextField

后端 未结 6 2408
攒了一身酷
攒了一身酷 2021-02-19 14:21

I\'m trying to figure out how to add a 1 pixel stroke gray border to my UISearchBar in my app. The Facebook Messenger app accomplishes this quite well. (see pic below).

6条回答
  •  逝去的感伤
    2021-02-19 14:28

    This work fine:

    UITextField *txtSearchField = [yourSearchBar valueForKey:@"_searchField"];
    [txtSearchField setBorderStyle:UITextBorderStyleRoundedRect];
    txtSearchField.layer.cornerRadius = 4;
    txtSearchField.layer.borderWidth = 1.0f;
    txtSearchField.layer.borderColor = [[UIColor colorWhatYouWant] CGColor]; 
    

    do not forget #import

提交回复
热议问题