1、在viewDidLoad中添加
// 重写UITableView的方法是分割线从最左侧开始
if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[_tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([_tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[_tableView setLayoutMargins:UIEdgeInsetsZero];
}2、重写下面的方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}其它:
关于UITableView中右箭头
cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button;
cell.accessoryType = UITableViewCellAccessoryCheckmark;//cell右边的形状是对号;UITableView分割线样式与颜色
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
_tableView.separatorColor = [UIColor colorWithRed:221/255.0f green:221/255.0f blue:221/255.0f alpha:0.5];UITableViewCell中ImageView的大小和位置
UIImage *icon = [UIImage imageNamed:[dic objectForKey:@"image"]];
CGSize itemSize = CGSizeMake(40, 40);
UIGraphicsBeginImageContextWithOptions(itemSize, NO,0.0);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[icon drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
本文介绍如何在 iOS 开发中使用 UITableView,并提供了设置分割线样式、颜色及移除默认边距的具体实现方法。此外还介绍了如何调整 UITableViewCell 的显示样式,包括移除默认的布局边距、更改单元格内的图标大小与位置等。
1万+

被折叠的 条评论
为什么被折叠?



