UITableViewCell自定义右边的文字以及更改左边图片的大小
来源:互联网 发布:js input 禁止光标 编辑:程序博客网 时间:2024/05/23 17:29
很多时候,uitabeleviewcell自身的功能已经满足我们项目中很多cell的需要,因此我们不需要自定义一个cell增加不必要的麻烦,但是随着ios7之后,很多程序的主流图片都是圆形,今天我们就来看一看如何不用自定义cell就能更改cell左边图片大小。
首先我们需要建立一个继承uitableviewcontroller的控制器,在返回cell那个方法里实现如下代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *dentifier=@"cellforappliancelist"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:dentifier]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:dentifier]; // cell.accessoryType=UITableViewCellStyleSubtitle; } cell.textLabel.text=@"配电室办公用电2楼照明"; cell.textLabel.font=[UIFont systemFontOfSize:15]; cell.detailTextLabel.text=@"[在线]"; cell.imageView.image=[UIImage imageNamed:@"暂代头像"]; cell.detailTextLabel.font=[UIFont systemFontOfSize:13]; //暂时加入一个label,后期用代码或者xib来自定义cell,用来优化cell的内存 UILabel *label=[[UILabel alloc]init]; label.text=@"优"; label.font=[UIFont systemFontOfSize:12]; label.textColor=[UIColor grayColor]; [label sizeToFit]; label.frame=CGRectMake(SCREEN_WIDTH - label.frame.size.width-15, 7, label.frame.size.width, label.frame.size.height); [cell.contentView addSubview:label]; //设置cell.imageview的宽高 CGSize itemSize = CGSizeMake(35, 35); UIGraphicsBeginImageContext(itemSize); CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height); [cell.imageView.image drawInRect:imageRect]; cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return cell;}
看一下显示效果吧
0 0
- UITableViewCell自定义右边的文字以及更改左边图片的大小
- UIButton(左边图片右边文字)
- uitableviewcell编辑模式自定义左边的图片按钮
- 自定义UITableViewCell上的图片文字
- 点击(鼠标经过)左边的文字,右边出现相应的图片
- android(安卓) 左边图片右边文字的button (按钮)
- ios UIButton 文字左边,图片右边排列
- 左边显示图片的路径,右边显示图片的情况
- iOS自定义Button如何在按钮中把文字放左边,图片放右边
- iOS UITableViewCell 的 imageView大小更改
- 更改图片的大小
- 实现一个imagebutton, 左边为图片,右边为文字
- Button 左边图片右边文字居中显示样式
- 按钮 图片调整到右边 文字到左边
- 新浪微博开发八(自定义标题按钮,解决图片在文字右边的问题)
- CMS图片对应文字以及设置固定的大小
- IOS自定义图片放右边的Button
- Android中如何设置RadioButton在文字的右边,图标在左边
- Json的解析简记
- The request sent by the client was syntactically incorrect
- Android中的动画,自定义补间动画
- floodFill函数
- 【php】include、include_once、require、require_once的区别
- UITableViewCell自定义右边的文字以及更改左边图片的大小
- ORA-01000:超出打开游标的最大数 的解决办法(C#)
- 关于CPU Cache——程序猿需要知道的那些事
- IOS开发—CALayer介绍
- Android 你应该知道的学习资源 进阶之路贵在坚持
- Gson
- 实现从区间产生不重复的随机数 - JS 实现
- UGUI(三)无限循环列表
- keil5 pack install 下载地址