Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 317931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:31:23+00:00 2026-05-12T08:31:23+00:00

I have a UISearchBar that has a cancel button (it’s displayed using -(void)setShowsCancelButton:animated ).

  • 0

I have a UISearchBar that has a cancel button (it’s displayed using -(void)setShowsCancelButton:animated). I’ve changed the tintColor of the search bar like this in an attempt to get a grayish searchbar:

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
searchBar.tintColor = [UIColor colorWithWhite:0.8 alpha:1.0];

This is what it looks like now – notice how the cancel button is also gray: http://twitpic.com/c0hte

Is there a way to set the color of the cancel button separately so it looks more like this: http://twitpic.com/c0i6q

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:31:23+00:00Added an answer on May 12, 2026 at 8:31 am

    What you want to do is pretty tough. There is no built-in hook to get at the cancel button.

    However, there are a couple of options if you are willing to jimmy open the hood.

    First off, UISearchBar is a UIView, and the Cancel button is also a view, which is added into the search bar as a subview, just as you would expect.

    I have experimented a little, and can tell you that when the button is onscreen it has a size of 48,30.

    So in viewWillAppear, you can do something like this:

    1. Find the cancel button view in [searchBar subviews] by looking for one with size 48,30. (There only seems to be one — this could change…) You could be doubly careful and look for one that is in approximately the correct position (differs in landscape and portrait).

    2. Add a subview to the cancel button.

    3. The subview should be a UIControl (so that you can set enabled = NO, in order to make sure touch events get to the actual cancel button)

    4. It needs to have the right color and rounded corners; you will need to fudge the size for reasons I don’t yet understand (55,30 seems to work)

    5. This will work if searchBar.showsCancelButton is always YES; if you want it to disappear when not editing the search string, you will need to find a hook to add the overlay each time the cancel button appears.

    6. As you can see, this is some ugly tinkering. Do it with eyes wide open.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 205k
  • Answers 205k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Just call A.this.hello() May 12, 2026 at 9:01 pm
  • Editorial Team
    Editorial Team added an answer I found the project javaparser, which parses a single java… May 12, 2026 at 9:01 pm
  • Editorial Team
    Editorial Team added an answer The general pattern that is followed nowadays is: Database ->… May 12, 2026 at 9:01 pm

Related Questions

I have a UISearchBar that has a cancel button (it's displayed using -(void)setShowsCancelButton:animated ).
Ok so I have a UIViewTable and a UISearchBar with two scope buttons. The
I have a subclass of UITableViewController. I have code that can add/remove a UISearchBar
I have a UISearchBar and on the delegate method I hide the keyboard when
I am creating an iPhone app which I would like to have a similar

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.