iOS:如何制作多列表格 [英] iOS: How To make multiple column table

查看:178
本文介绍了iOS:如何制作多列表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在iOS 7和8上使用uitableview制作表格. 表格如下图所示

I am trying to make a table using uitableview on iOS 7 and 8 . The table is like the image below

我尝试使用uitableviewCell进行操作,但是在iPhone和iPad上的标签调整不佳..加上自动布局很难处理.

I've tried doing it using uitableviewCell but the labels didn't adjusted well in iphone and iPad .. plus the auto layout was pain to handle.

我的问题是..无论如何,即使使用uicollectionView,我也可以做到这一点.请详细说明.

My question is.. Is there anyway that I can do this even with uicollectionView.. and how in details please.

任何帮助将不胜感激

推荐答案

就像一个例子.显然,您必须配置很多东西,但是我认为这是一个很好的起点:

like an example. Obvisously there are many things you must configure, but I think is good start point:

.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

如果要纵向和横向工作,可能需要编写方法才能正常工作. (旋转).但这是Rotate方法中的相同代码.

You might need to write the methods to work properly if you want work in portrait and landscape. (rotate). But It´s the same code in the rotate methods.

这篇关于iOS:如何制作多列表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆