zoukankan      html  css  js  c++  java
  • IOS开发之TableView替换默认的checkmark为自定义图像

    直接上代码:


    On cellForRowAtIndexPath:

    UIButton*button =[UIButton buttonWithType:UIButtonTypeCustom];CGRect frame =CGRectMake(0.0,0.0, image.size.width, image.size.height);
    button.frame = frame;[button setBackgroundImage:image forState:UIControlStateNormal];[button addTarget:self action:@selector(checkButtonTapped:event:)  forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor =[UIColor clearColor];
    cell.accessoryView = button;

    checkButtonTapped:event: Method:

    -(void)checkButtonTapped:(id)sender event:(id)event
    {NSSet*touches =[event allTouches];UITouch*touch =[touches anyObject];CGPoint currentTouchPosition =[touch locationInView:self.tableView];NSIndexPath*indexPath =[self.tableView indexPathForRowAtPoint: currentTouchPosition];if(indexPath != nil){[self tableView: self.tableView accessoryButtonTappedForRowWithIndexPath: indexPath];}}

    accessoryButtonTappedForRowWithIndexPath: Method

    -(void)tableView:(UITableView*)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath*)indexPath
    {NSMutableDictionary*item =[dataArray objectAtIndex:indexPath.row];
    
    BOOL checked =[[item objectForKey:@"checked"] boolValue];[item setObject:[NSNumber numberWithBool:!checked] forKey:@"checked"];UITableViewCell*cell =[item objectForKey:@"cell"];UIButton*button =(UIButton*)cell.accessoryView;UIImage*newImage =(checked)?[UIImage imageNamed:@"unchecked.png"]:[UIImage imageNamed:@"checked.png"];[button setBackgroundImage:newImage forState:UIControlStateNormal];}


  • 相关阅读:
    .NET简谈插件系统开发模式
    .NET实现之(自动更新)
    .NET简谈互操作(二:先睹为快)
    .NET实现之(WebBrowser数据采集—基础篇)
    .NET简谈设计模式之(观察者模式)
    .NET简谈平台大局观
    .NET实现之(简易ORM)
    .NET简谈面向接口编程
    .NET简谈事件与委托
    .NET实现之(WebBrowser数据采集—终结篇)
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3233778.html
Copyright © 2011-2022 走看看