zoukankan      html  css  js  c++  java
  • UITableview自定义accessory按钮和ImageView大小一致

        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
            cell.accessoryType = UITableViewCellAccessoryDetailButton;
            cell.textLabel.font = [UIFont systemFontOfSize:19.0];
            
            UIImage *image = [UIImage imageNamed:@"england"];
            UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
            CGRect frame = CGRectMake(0.0,0.0,15,15);
            button.frame = frame;
            [button setBackgroundImage:image forState:UIControlStateNormal];
            button.backgroundColor = [UIColor clearColor];
            cell.accessoryView = button;
             [button addTarget:self action:@selector(btnClicked:event:) forControlEvents:UIControlEventTouchUpInside];
        }
    - (void)btnClicked:(id)sender event:(id)event
    {
        NSSet * touches = [event allTouches];
        UITouch * touch = [touches anyObject];
        CGPoint currentTouchPosition = [touch locationInView:self.countriesTableView];
        NSIndexPath * indexPath = [self.countriesTableView indexPathForRowAtPoint:currentTouchPosition];
        if(indexPath != nil)
        {
            [self tableView:self.countriesTableView accessoryButtonTappedForRowWithIndexPath:indexPath];
        }
    }

    设置imageView大小

        cell.imageView.image = [MainTableViewController scale:item.flag toSize:CGSizeMake(115, 75)];
    + (UIImage *)scale:(UIImage *)image toSize:(CGSize)size
    {
        UIGraphicsBeginImageContext(size);
        [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
        UIImage * scaledImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return scaledImage;
    }
  • 相关阅读:
    强大的mono.cecil
    关于svn不能cleanup的问题
    SVN项目,快速查看项目的当前版本号
    jQuery选择器总结
    将Excel数据导入mysql数据库的几种方法
    SpringMVC表单标签简介
    mybatis动态SQL语句
    mysql时间格式化,按时间段查询MYSQL语句
    深入了解ios系统机制
    Eclipse 官方简体中文语言包下载地址及安装方法
  • 原文地址:https://www.cnblogs.com/fengmin/p/5482507.html
Copyright © 2011-2022 走看看