tags:

views:

432

answers:

2

Hello Everyone, Hope you all are fine and also in best of your moods.

I have a little problem kindly help me to get its solution.

my Problem is:

I am using vertical search in my application, using method sectionIndexTitlesForTableView() of tableview i get all Character listed from top to bottom at rightside.

But this letters have fixed color. i need to change this color. Since i newbie i don't know how to deal with it.

Please help to get solution.

Thanks, and sorry if you found me with wrong english.

+1  A: 

There is no supported way to do this. Even if you had access to the index view (which you don't easily), it would not be possible because there is no NSAttributedString on iPhone, so you couldn't return color information.

The best way to achieve this is to turn off the tableview's index and generate your own from scratch, floating it over top of the tableview. But I would not recommend this approach for a new iPhone developer. It is best to spend some serious time learning to build UIs the way Apple intends you to. Once you understand Apple's UI and how it's implemented, then you can make informed decisions about whether you should break the UI rules.

Rob Napier
A: 

To get your desired effect you should implement tableView:viewForHeaderInSection: inside of your UITableViewDelegate. From here you can construct a custom UIView which displays exactly what you want. The way you create this view is up to you, and there are a couple of options:

  • You can use UILabels to display your text. These labels can be added directly to your custom view. You sadly will not be able to use a single UILabel as this class provides no functionality for drawing your text in more than one color.
  • You can use the drawTextInRect: method of UILabel instead of adding them as subviews to your custom view.
  • You can also draw all of your text manually using something like CGContextShowTextAtPoint.
Sebastian Celis