cmo*_*mos 46 iphone uitableview
我有一个带有字母索引的表格视图,并使用侧面字母表快速浏览列表.对于那些不熟悉的人,使用这个:
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
Run Code Online (Sandbox Code Playgroud)
我的问题是我的应用程序刚剥了皮黑.所以现在很难看到侧面的字母.
我无法弄清楚如何改变字母表的颜色.如果可能的话,我希望它是'白色的'.
sun*_*ppy 61
如果您的最低iOS版本低于6.0,则可以使用sectionIndexColor
属性UITableView
.
用于表视图索引文本的颜色.
@property(非原子,保留)UIColor*sectionIndexColor
讨论:
表视图可以在视图的侧面显示索引,使用户可以更轻松地快速导航表的内容.此属性指定用于此区域中显示的文本的颜色.
更新日期2014.1.13
我找到了一个开源的第三方库:GDIIndexBar来帮助自定义索引的外观.
pau*_*erd 32
据我所知,不可能自定义索引中显示的文本的颜色,我能够最接近的是能够修改背景颜色和索引的字体.
Erica Sadun的iPhone开发者手册中有一些代码,展示了如何访问UITableViewIndex视图(一个未记录的类).如果有的话,可以在本书的第175页找到对它的引用.这样可以访问背景颜色和字体.您可以在此处查看与此课程相关的非官方文档.
警告这是未记录的类的未记录使用,因此您需要谨慎使用它.
以下是食谱中的代码片段,稍作修改:
- (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...
}
Run Code Online (Sandbox Code Playgroud)
这说明了如何访问和UITableViewIndex视图以及在某些方面对其进行修改.看起来该视图没有任何子视图,因此可能会使用索引标题数组进行一些自定义绘制.
它并不完美,但希望它能有所帮助.
保罗
Pau*_*bre 17
适用于iOS7或更高版本:
self.tableView.sectionIndexColor = [UIColor whiteColor];
self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
Mar*_*n_G 11
我遇到了同样的问题,并且发现了一种方法,虽然这是使用未记录的类和方法,所以在尝试将其上传到App Store之前再考虑一次.我应该说我只用iOS5试过这个,所以我不知道它是否适用于以前的版本.
我借用并修改了Erica Saunders食谱示例,以便它现在将文本颜色更改为红色:
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
for(UIView *view in [tv subviews])
{
if([[[view class] description] isEqualToString:@"UITableViewIndex"])
{
[view performSelector:@selector(setIndexColor:) withObject:[UIColor redColor]];
}
}
//rest of cellForRow handling...
}
Run Code Online (Sandbox Code Playgroud)
Mag*_*nus 11
我们已成功使用以下代码:
for(UIView *view in [tableView subviews]) {
if([view respondsToSelector:@selector(setIndexColor:)]) {
[view performSelector:@selector(setIndexColor:) withObject:[UIColor whiteColor]];
}
}
Run Code Online (Sandbox Code Playgroud)
哪个工作正常 - 它与Mooglas的答案非常相似 - 但不要使用"UITableViewIndex"这个词.
您可以为tableView设置色调颜色.
[[UITableView appearance] setTintColor:[UIColor purpleColor]];
Run Code Online (Sandbox Code Playgroud)
斯威夫特 5:
tableView.sectionIndexColor = .red
tableView.sectionIndexBackgroundColor = .clear
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
32951 次 |
最近记录: |