2011-10-21 203 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

很不錯的解決方案。 –