iOS:如何制作多个列表

我想在iOS 7和8上使用uitableview制作表格。 表格就像下面的图片

表

我已经尝试使用uitableviewCell做,但标签没有在iPhone和iPad中调整得很好。加上自动布局很难处理。

我的问题是..有无论如何,我可以做到这一点即使与uicollectionView ..以及如何详细请。

任何帮助将不胜感激

就像一个例子。 显然有很多事情你必须configuration,但我认为是好的起点:

.h文件:

#import <UIKit/UIKit.h> @interface OKCustomFiveLabelsTableViewCell : UITableViewCell // Here is the place to send through the tableViewDelegate all info about the cell. @property (nonatomic, strong) NSDictionary *dictInfo; @end 

.m文件

 #import "OKCustomFiveLabelsTableViewCell.h" #define FIRST_LABEL_PERCENT 0.15 #define SECOND_LABEL_PERCENT 0.3 #define THIRD_LABEL_PERCENT 0.2 #define FOURTH_LABEL_PERCENT 0.2 #define FIFTH_LABEL_PERCENT 0.15 //the sum of this five must be 1 @interface OKCustomFiveLabelsTableViewCell () @property (nonatomic, strong) UILabel *firstLabel; @property (nonatomic, strong) UILabel *secondLabel; @property (nonatomic, strong) UILabel *thirdLabel; @property (nonatomic, strong) UILabel *fourthLabel; @property (nonatomic, strong) UILabel *fifthLabel; @end @implementation OKCustomFiveLabelsTableViewCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { CGFloat width = [UIScreen mainScreen].bounds.size.width; self.firstLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, width *FIRST_LABEL_PERCENT, 25)]; //Configure here your label // It´s good idea Use: NSTextAlignamentCenter [self.contentView addSubview:self.firstLabel]; self.secondLabel= [[UILabel alloc] initWithFrame:CGRectMake(width *FIRST_LABEL_PERCENT, 5, width *SECOND_LABEL_PERCENT, 25)]; //Configure here your label [self.contentView addSubview:self.secondLabel]; self.thirdLabel= [[UILabel alloc] initWithFrame:CGRectMake(width *(FIRST_LABEL_PERCENT + SECOND_LABEL_PERCENT), 5, width *THIRD_LABEL_PERCENT, 25)]; //Configure here your label [self.contentView addSubview:self.thirdLabel]; self.fourthLabel= [[UILabel alloc] initWithFrame:CGRectMake(width *(FIRST_LABEL_PERCENT + SECOND_LABEL_PERCENT+THIRD_LABEL_PERCENT), 5, width *FOURTH_LABEL_PERCENT, 25)]; //Configure here your label [self.contentView addSubview:self.fourthLabel]; self.fifthLabel= [[UILabel alloc] initWithFrame:CGRectMake(width *(FIRST_LABEL_PERCENT + SECOND_LABEL_PERCENT+THIRD_LABEL_PERCENT+FOURTH_LABEL_PERCENT), 5, width *FIFTH_LABEL_PERCENT, 25)]; //Configure here your label [self.contentView addSubview:self.fifthLabel]; } return self; } -(void)setDictInfo:(NSDictionary *)dictInfo { self.fifthLabel.text = [dictInfo valueForKey:@"identyNumber"]; self.secondLabel.text = [dictInfo valueForKey:@"name"]; self.thirdLabel.text = [dictInfo valueForKey:@"amount"]; self.fourthLabel.text = [dictInfo valueForKey:@"time"]; self.fifthLabel.text = [dictInfo valueForKey:@"type"]; _dictInfo = dictInfo; } @end 

如果您想要在纵向和横向上工作,则可能需要编写方法才能正常工作。 (旋转)。 但在旋转方法中它是相同的代码。

你有没有尝试过一些第三方组件? 在GitHub上有很好的演示MDSpreadView组件。

链接: https //github.com/mochidev/MDSpreadViewDemo

一个方法来使多个列表将是有:

1)每个项目的不同的UICollectionViewCell

2)单独的标题视图,只是为了不堵塞非数据信息的数据源。

3)仔细pipe理每个部分中的单元类别和位置,每个部分是一行,每个单元格是一个列条目。

在你的情况下,我认为,自定义表格视图单元格是你最好的select。 您可以创build并将它们排列在故事板中,并设置适当的IBOutlet。

你可以按照这个教程 ,这个模式真的很好。