UITableview自定义accessory按钮和ImageView大小一致
自定义 大小 按钮 一致 ImageView UITableView
2023-09-11 14:18:58 时间
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; }
相关文章
- Metalama简介3.自定义.NET项目中的代码分析
- Word控件Spire.Doc 【页面背景】教程(6) ;如何设置页面边框的位置和自定义样式
- WPF 自定义控件 Loaded 导致的设计器异常 解决方案
- Android 最新实现沉浸式状态栏、底部导航栏、任务栏及Actionbar添加搜索框及自定义菜单等功能的实现完整代码
- 微信小程序 - 页面插入添加 Banner 广告超详细教程(支持自定义样式、位置、大小等)及注意事项
- 微信小程序轮子 - 自定义中间凸起底部导航栏(只需渲染一次组件 | 性能高 | 灵活)
- Vue - 实现信纸输入写作,类似写明信片时的一张背景图片 + 横格纸效果(信纸格子与文字自动对齐、支持自定义背景图、文字或横线大小与颜色,一切由您 DIY 自定义样式)纯CSS完成支持任何vue项目
- SpringBoot 使用自定义注解 +AOP+Redis 实现接口限流
- Android自定义View:MeasureSpec的真正意义与View大小控制
- VC实现自定义控件步骤
- 在ASP.NET MVC中使用Knockout实践06,自定义验证、异步验证
- 如何用 Kubernetes 自定义资源?
- 教你如何在 map 上添加自定义控件
- Android学习小Demo一个显示行线的自定义EditText
- OkHttp自定义重试次数
- Powerfuzzer—自动化的自定义Web Fuzzer
- Swift -banner滚动图自定义
- Vue3 编写自定义指令插件