点击tableView中的cell 相应的改变navgationbar的背景色
来源:互联网 发布:全球票房数据库 编辑:程序博客网 时间:2024/04/28 17:18
1.让tableView分组显示 并设置navgationbar的title
-(tableview *)init{ if(self = [super initWithStyle:UITableViewStyleGrouped]) { self.title = @"ColorTransitation"; } return self ;}
2.tableView 所需的数据
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return [sectionArray count];}-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [[sectionArray objectAtIndex:section] count];}-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ColorTranslation"]; if(cell == nil) { cell = [[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:@"ColorTranslation"]; } NSInteger row = [indexPath row]; NSInteger section = [indexPath section]; NSArray *arrays = [[[sectionArray objectAtIndex:section] objectAtIndex:row] componentsSeparatedByString:@"#"]; cell.text = [arrays objectAtIndex:0]; cell.textColor = [self getColor:[arrays objectAtIndex:1]]; return cell ;}
3。定义 得到颜色的函数
-(UIColor *)getColor:(NSString *)hexColor{ unsigned int red,green,blue; NSRange range ; range.length = 2 ; range.location = 0 ; [[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&red]; range.location = 2 ; [[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&green]; range.location = 4 ; [[NSScanner scannerWithString:[hexColor substringWithRange:range]]scanHexInt:&blue]; return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f]; }
4. tableView 的委托方法
-(void)deselect{ [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSInteger row = [indexPath row]; NSInteger section = [indexPath section]; NSArray *arrays = [[[sectionArray objectAtIndex:section]objectAtIndex:row] componentsSeparatedByString:@"#"]; self.navigationController.navigationBar.tintColor = [self getColor:[arrays objectAtIndex:1]]; [self performSelector:@selector(deselect) withObject:NULL afterDelay:0.5];}
5.显示 tableView
-(void)createSectionList:(id)wordArray{ sectionArray = [[[NSMutableArray alloc]init]retain]; for(int i=0;i<26;i++) [sectionArray addObject:[[[NSMutableArray alloc]init]retain]]; for(NSString *word in wordArray) { if([word length]==0) continue ; NSRange range = [ALPHA rangeOfString:[[word substringToIndex:1]uppercaseString]]; [[sectionArray objectAtIndex:range.location] addObject:word]; }}-(void)loadView{ [super loadView]; NSString *pathname = [[NSBundle mainBundle] pathForResource:@"crayons" ofType:@"txt" inDirectory:@"/"]; NSString *wordstring = [NSString stringWithContentsOfFile:pathname]; NSArray *wordArray = [[wordstring componentsSeparatedByString:@"\n"]retain]; [self createSectionList:wordArray];}
- 点击tableView中的cell 相应的改变navgationbar的背景色
- 重写cell的frame,空隙处显示tableView背景色
- 点击tableview里的cell后改变cell的背景图片
- tableview 自定义cell 点击cell改变cell中的label.text的字体颜色,cell复用出现问题
- tableview 自定义cell 点击cell改变cell中的label.text的字体颜色,cell复用出现问题
- TableView 点击cell,改变选中cell的高度
- TableView 点击cell,改变选中cell的高度
- cell选中的背景色
- tableview 点击cell改变cell中的label.text的字体颜色,cell复用出现问题的解决方案
- tableview 点击cell改变cell中的label.text的字体颜色,cell复用出现问题的解决方案2
- 点击listview的时候listitem不改变背景色
- 改变对话框的背景色
- 改变Button的背景色
- 改变控件的背景色
- 改变CFrameWnd的背景色
- 改变对话框的背景色
- 改变对话框的背景色
- 改变对话框的背景色
- 统计文件中汉字和英文出现次数
- 推荐15款很棒的文本编辑器——程序员专用
- SQL SERVER 2008配置邮件通知功能
- Git学习笔记(五) Git重置
- LDD3源码分析之字符设备驱动程序
- 点击tableView中的cell 相应的改变navgationbar的背景色
- 提高PHP代码质量36计
- qt分隔器(Splitters)
- 高逸峰, 好样的!
- IT职场寓言:四种兔子最易输
- QT编写的qq抽屉效果
- 8月夜空将上演流星雨、月掩金星等天文现象
- GraphicsView坐标系(有错 视图坐标系和widget坐标系一样)
- teradata与oracle的with子句对比