• 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;
    }
  • 相关阅读:
    BootStrap练习
    表单控件练习
    K近邻算法原理
    CSS 边框和颜色
    SVG平移和旋转
    SVG进阶练习
    SVG路标(marker)
    SVG 曲线与文字
    python函数与异常处理
    if-elif-else分支判断语句(附加continue和break)---举例说明
  • 原文地址:https://www.cnblogs.com/fengmin/p/5482507.html
Copyright © 2020-2023  润新知