我正在iphone中做一个阅读器应用程序,有一个叫做低光视图的按钮(夜间模式),当用户点击按钮时,它自动选择视图的背景,我的阅读器视图是tableview,我有两个tableview in一个视图,两个tableview显示不同的内容,我知道如何在按钮单击中更改tableview的背景,我使用此代码。
table1st.backgroundColor = [UIColor blackColor];
table2nd.backgroundColor = [UIColor blackColor];
当用户点击按钮时,它会改变tableview的背景,我的问题是
在用户点击后更改背景后,它会显示两个tableviews的黑色背景,但是当用户重定向到应用程序的另一个视图并返回到阅读器视图时,它会自动将背景更改为默认值(我的默认值是clear-color,我在tableview单元格属性中设置它。)我不想这样。
当第一个tableview开始滚动时,它会变为默认背景,但是在第二个tableview的情况下,没有问题,当滚动时,它没有改变默认状态。
最后一个问题是如何使用tableviews的背景更改来更改tableview单元格的文本标签颜色,并且我在两个tableview单元格中都有一个标签,标签中也有一些文本,i想要将标签的颜色更改为白色,也像文本标签颜色一样。
我如何解决这些问题?请帮助我。 提前谢谢。
编辑:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
readCell *cell = (readCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"readCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.malayalamVerse.hidden = YES;
cell.malayalamVerse.backgroundColor = [UIColor clearColor];
self.table.tableFooterView = _btnTablemoreview;
self.table.tableFooterView.userInteractionEnabled = YES;
}
/*table.separatorColor = [UIColor clearColor];
[cell setBackgroundColor:[UIColor colorWithRed:177 green:148 blue:106 alpha:1]];
cell.chapterAndVerse.text = [NSString stringWithFormat:@"%@.%d ",delegate.selectedChapter,indexPath.row+1];
cell.textLabel.font = [UIFont fontWithName:@"Georgia" size:16];
UIFont *fnt = [UIFont fontWithName:@"Georgia" size:16];
CGSize textSize;
if([[delegate.allSelectedVerseMalayalam objectAtIndex:indexPath.row] sizeWithZFont:[[FontManager sharedManager] zFontWithName:@"testfont" pointSize:17] constrainedToSize:CGSizeMake(220,1000) lineBreakMode:UILineBreakModeWordWrap].height > [[delegate.allSelectedVerseEnglish objectAtIndex:indexPath.row] sizeWithFont:fnt constrainedToSize:CGSizeMake(220,1000) lineBreakMode:UILineBreakModeWordWrap].height)
{
textSize = [[delegate.allSelectedVerseMalayalam objectAtIndex:indexPath.row] sizeWithZFont:[[FontManager sharedManager] zFontWithName:@"testfont" pointSize:17] constrainedToSize:CGSizeMake(220,1000) lineBreakMode:UILineBreakModeWordWrap];
}
else
{
textSize = [[delegate.allSelectedVerseEnglish objectAtIndex:indexPath.row] sizeWithFont:fnt constrainedToSize:CGSizeMake(220,1000) lineBreakMode:UILineBreakModeWordWrap];
}*/
if(tableView == table)
{
UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
// myBackView.backgroundColor = [UIColor colorWithRed:250.0 green:248.0 blue:192.0 alpha:1.0];
[myBackView setBackgroundColor:[UIColor clearColor]];
cell.selectedBackgroundView = myBackView;
[myBackView release];
cell.textLabel.highlightedTextColor = [UIColor colorWithRed:1 green:1 blue:0.75 alpha:1];
table.backgroundColor = [UIColor clearColor];
table.separatorColor = [UIColor clearColor];
cell.chapterAndVerse.text = [NSString stringWithFormat:@"%@.%d ",delegate.selectedChapter, indexPath.row+1];
cell.chapterAndVerse.backgroundColor= [UIColor whiteColor];
cell.chapterAndVerse.textColor = [UIColor brownColor];
cell.chapterAndVerse.font = [UIFont fontWithName:@"Georgia" size:14.0];
cell.chapterAndVerse.frame=CGRectMake(33, 6, 30.0, 12.0);
cell.textLabel.text = [NSString stringWithFormat:@" %@",[delegate.allSelectedVerseEnglish objectAtIndex:indexPath.row]];
cell.textLabel.font = [UIFont fontWithName:@"Georgia" size:15];
cell.textLabel.textColor = [UIColor darkGrayColor];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.backgroundColor = [UIColor clearColor];
return cell;
}
else if(tableView == tab)
{
UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
// myBackView.backgroundColor = [UIColor colorWithRed:250.0 green:248.0 blue:192.0 alpha:1.0];
[myBackView setBackgroundColor:[UIColor clearColor]];
cell.selectedBackgroundView = myBackView;
[myBackView release];
cell.textLabel.highlightedTextColor = [UIColor colorWithRed:1 green:1 blue:0.75 alpha:1];
cell.malayalamVerse.hidden = YES;
cell.malayalamVerse.backgroundColor = [UIColor clearColor];
// tab.backgroundColor = [UIColor clearColor];
tab.separatorColor = [UIColor clearColor];
cell.chapterAndVerse.frame = CGRectMake(0, 0,30.0,12.0);
cell.chapterAndVerse.text = [NSString stringWithFormat:@"%@.%d ",delegate.selectedChapter, indexPath.row+1];
cell.chapterAndVerse.backgroundColor= [UIColor whiteColor];
cell.chapterAndVerse.textColor = [UIColor brownColor];
cell.chapterAndVerse.font = [UIFont systemFontOfSize:7.0];
cell.textLabel.text = [NSString stringWithFormat:@" %@",[delegate.allSelectedVerseHindi objectAtIndex:indexPath.row]];
cell.textLabel.font = [UIFont fontWithName:@"Georgia" size:15];
cell.textLabel.textColor = [UIColor darkGrayColor];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.backgroundColor = [UIColor clearColor];
}
return cell;
}
读取单元格是我在xib中开发的tableview单元格,它打破了我想要更改fontcolor的标签。