UITableView的分割线从最左侧开始, 右箭头,分割线颜色; UITableViewCell中ImageView位置大小控制

来源:互联网 发布:dota2画质优化 编辑:程序博客网 时间:2024/05/22 16:07

1、在viewDidLoad中添加

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. // 重写UITableView的方法是分割线从最左侧开始  
  2.     if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {          
  3.         [_tableView setSeparatorInset:UIEdgeInsetsZero];  
  4.     }  
  5.     if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {  
  6.         [_tableView setLayoutMargins:UIEdgeInsetsZero];  
  7.     }  

2、重写下面的方法

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath  
  2. {  
  3.     if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {  
  4.         [cell setSeparatorInset:UIEdgeInsetsZero];  
  5.     }  
  6.     if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {  
  7.         [cell setLayoutMargins:UIEdgeInsetsZero];  
  8.     }  
  9. }  

其它:

关于UITableView中右箭头

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式  
  2. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素;  
  3. cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button;  
  4. cell.accessoryType = UITableViewCellAccessoryCheckmark;//cell右边的形状是对号;  

UITableView分割线样式与颜色

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;  
  2. _tableView.separatorColor = [UIColor colorWithRed:221/255.0f green:221/255.0f blue:221/255.0f alpha:0.5];  

UITableViewCell中ImageView的大小和位置

[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. UIImage *icon = [UIImage imageNamed:[dic objectForKey:@"image"]];  
  2. CGSize itemSize = CGSizeMake(40, 40);  
  3. UIGraphicsBeginImageContextWithOptions(itemSize, NO,0.0);  
  4. CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);  
  5. [icon drawInRect:imageRect];  
  6. cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();  
  7. UIGraphicsEndImageContext();  
0 0