如何在索引的 UITableView 中更改侧面字母的颜色? [英] How do I change the color of the side Alphabet in an indexed UITableView?

查看:31
本文介绍了如何在索引的 UITableView 中更改侧面字母的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有字母索引的表格视图,我正在使用侧边字母来快速浏览列表.对于那些不熟悉的人,使用这个:

I have a table view with an alphabetical index and am using the side alphabet to get through the list quickly. For those not familiar, that uses this:

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {

我的问题是我的应用程序刚刚变黑.所以现在很难看到侧面的字母了.

My problem is that my application has just been skinned black. And so now it's hard to see the alphabet letters on the side.

我不知道如何更改字母表的颜色.如果可能的话,我希望它是白色"的.

I can't figure out how to change the color of the alphabet. I'd like it to be 'white' if at all possible.

推荐答案

据我所知,很遗憾无法自定义索引中显示的文本的颜色,我所能做到的最接近的是可以修改索引的背景颜色和字体.

From what I can tell unfortunately it is not possible to customize the color of the text displayed in the index, the closest I've been able to come is being able to modify the background color and the font of the index.

在 Erica Sadun 的 iPhone 开发人员手册中有一些代码,它展示了如何访问 UITableViewIndex 视图(一个未记录的类).如果你有它,你可以在本书的第 175 页找到它的参考.这可以访问背景颜色和字体.您可以在此处查看与此类相关的非官方文档.

There is some code in the iPhone Developers cookbook by Erica Sadun which shows how to access the UITableViewIndex view (an undocumented class). You can find the reference to it on page 175 of the book if you have it. Which gives access to the background color and the font. You can see an unofficial document related to this class here.

警告这是对未记录类的未记录使用,因此您需要谨慎使用它.

WARNING This is undocumented use of an undocumented class so you need to be cautious about using it.

这是食谱中的一个代码片段,稍作修改:

Here is a code snippet from the cookbook with minor modifications:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {    

  for(UIView *view in [tv subviews])
  {
    if([[[view class] description] isEqualToString:@"UITableViewIndex"])
    {

      [view setBackgroundColor:[UIColor whiteColor]];
      [view setFont:[UIFont systemFontOfSize:14]];
    }
  }

  //rest of cellForRow handling...

} 

这说明了如何访问 UITableViewIndex 视图并在某些方面对其进行修改.看起来该视图没有任何子视图,因此很可能使用索引标题数组进行一些自定义绘图.

This illustrates how you can access and the UITableViewIndex view and modify it in some aspects. It looks like the view doesn't have any subviews so it is likely doing some custom drawing with the array of index titles.

它并不完美,但希望能有所帮助.

It's not perfect but hopefully it helps a little.

保罗

这篇关于如何在索引的 UITableView 中更改侧面字母的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆