2011-10-21 78 views
2

一些背景。我正在帮助我儿子学校的一群学生,他们想写一个简单的跟踪应用程序,管理学生在iPod Touch上使用的观察结果。iOS水平滚动日历

我只使用标准小部件完成非常基本的iOS开发,但我很乐意提供帮助。

我们通过并设计了应用程序的功能和界面,现在开始编程。我深深的地方在于,他们希望每天都有一个沿着屏幕底部的带子,作为显示日期和日期的小块,以及显示当天是否有观察结果的指示符。

我希望你们能指点我正确的方向,既可以是现有的小部件,也可以详细解释如何实现这一点。我尝试了几种方法,但没有运气。

我很感谢这方面的任何帮助,因为我知道这一定是常见的要求,但我正在努力克服这一点。

回答

5

我想我会张贴我的最终解决方案,以防其他人发现它有用。

在视图根视图控制器我添加了一个自定义的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; 

} 
+0

综合答案 –

+0

嗨卓然,我正在研究类似的组件,你的解决方案似乎与我现在有点卡住的地方有关。 我不知道你是否必须实现无限滚动作为这个项目的一部分? – ymotov

+0

我用了一个非常大的数字作为表格大小,然后只是动态地计算每个单元格的日期。我看不到任何其他方式。 – Zoran

1

恕我直言,你应该创建一个你想要显示每个日期的视图。创建类似于

@interface DayView : UIView { 

您可以用nib实现它,或者在drawRect方法中以编程方式创建所有内容。

当它转到您的Xcode文档并搜索UIScrollView。 Xcode会提供你的代码示例,使用项目“滚动”来了解如何使用scrollView。在这个示例中,他们滚动图片,并用我们的自定义DayView替换它们。

祝你好运!

+0

我选择了UITableView的方法的原因是,让懒加载功能,我需要,我可以使用UITableView出队功能,在UIScrollView中,我必须自己实现相同的行为。事实是,凭借我有限的经验,我使用了第一种有效的技术。 – Zoran

+0

很不错的解决方案。 –