我想我會張貼我的最終解決方案,以防其他人發現它有用。
在視圖根視圖控制器我添加了一個自定義的UITableViewController,它基本上旋轉表90度,然後旋轉每個表格單元-90度。它做我想要的是非常簡單。
根視圖控制器的代碼。這將設置表的大小和位置:
scrollingDateViewController=[[ScrollingDateViewController alloc] initWithNibName:@"ScrollingDateView" bundle:[NSBundle mainBundle]];
CGRect rect=CGRectMake(0,330,320,100);
scrollingDateViewController.view.frame=rect;
scrollingDateViewController.view.backgroundColor=[UIColor clearColor];
scrollingDateViewController.delegate = self;
[self.view addSubview:scrollingDateViewController.view];
鑰匙密碼ScrollingDateViewController。這使工作臺90度,每個單元-90輩分:
- (void)viewDidLoad {
today = [[NSDate alloc] init];
CGRect rect=self.view.frame;
myTableView.frame=rect;
myTableView.layer.transform = CATransform3DRotate(CATransform3DIdentity,1.57079633,0,0,1);
myTableView.backgroundColor=[UIColor clearColor];
myTableView.separatorColor=[UIColor clearColor];
myTableView.frame=rect;
myTableView.rowHeight=44; // cellWidth
myTableView.showsHorizontalScrollIndicator=NO;
myTableView.showsVerticalScrollIndicator=NO;
myTableView.separatorColor=nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"tableCell"];
if(!cell){
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"tableCell"];
cell.contentView.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"cell_back.png"]];
cell.contentView.transform = CGAffineTransformMakeRotation(-1.57079633);
cell.selectionStyle=UITableViewCellSelectionStyleGray;
// Add background image view
CGRect rect=CGRectZero;
UIImageView *imgView=[[UIImageView alloc] initWithFrame:rect];
imgView.contentMode=UIViewContentModeScaleToFill;
imgView.layer.transform = CATransform3DRotate(CATransform3DIdentity,-1.57079633,0,0,1);
imgView.tag=101;
[cell addSubview:imgView];
rect.origin.x=0;
rect.origin.y=0;
rect.size.height=80;
rect.size.width=44;
imgView.frame=rect;
[imgView release];
// Add Day Label
UILabel *dayLabel=[[UILabel alloc] initWithFrame:rect];
dayLabel.layer.transform = CATransform3DRotate(CATransform3DIdentity,-1.57079633,0,0,1);
dayLabel.tag=102;
dayLabel.font = [UIFont fontWithName:@"Geogrotesque-Medium" size:14.0];
dayLabel.textAlignment=UITextAlignmentCenter;
dayLabel.backgroundColor=[UIColor clearColor];
dayLabel.textColor=[UIColor darkGrayColor];
[cell addSubview:dayLabel];
rect.origin.x=40;
rect.origin.y=0;
rect.size.height=44;
rect.size.width=20;
dayLabel.frame=rect;
[dayLabel release];
// Add Date Label
UILabel *dateLabel=[[UILabel alloc] initWithFrame:rect];
dateLabel.layer.transform = CATransform3DRotate(CATransform3DIdentity,-1.57079633,0,0,1);
dateLabel.tag=103;
dateLabel.font = [UIFont fontWithName:@"Geogrotesque-Bold" size:18.0 ];
dateLabel.textAlignment=UITextAlignmentCenter;
dateLabel.backgroundColor=[UIColor clearColor];
dateLabel.textColor=[UIColor darkGrayColor];
[cell addSubview:dateLabel];
rect.origin.x=55;
rect.origin.y=0;
rect.size.height=44;
rect.size.width=20;
dateLabel.frame=rect;
[dateLabel release];
}
UILabel *label=(UILabel*)[cell viewWithTag:102];
label.text= [self getDayString:displayDate];
label=(UILabel*)[cell viewWithTag:103];
label.text= [self getDateString:displayDate];
return cell;
}
綜合答案 –
嗨卓然,我正在研究類似的組件,你的解決方案似乎與我現在有點卡住的地方有關。 我不知道你是否必須實現無限滾動作爲這個項目的一部分? – ymotov
我用了一個非常大的數字作爲表格大小,然後只是動態地計算每個單元格的日期。我看不到任何其他方式。 – Zoran