-1

写真でわかるように、CGMake を使用して 52 週のボタンを作成します。

これは私の週表示カレンダーです

ここに私のコードがあります

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
    int rows = 13, columns = 4 ;
UIView *buttonView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 80*columns, 32*rows)];
int currentTag = 0;

for (int y = 0; y < rows; y++) {
    for (int x = 0; x < columns; x++) {

        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];  
        button.backgroundColor=[UIColor colorWithRed: 201.0/255.0 green: 201.0/255.0 blue:201.0/255.0 alpha: 1.0];
        button.tag = currentTag;
        currentTag++;
        [button.layer setBorderColor: [[UIColor whiteColor] CGColor]];
        [button.layer setBorderWidth: 0.5];
        if (x == 0 && y == 3) {
            [button setBackgroundColor:[UIColor redColor]];
        } else if(x == 1 && y == 5) {
            [button setBackgroundColor:[UIColor redColor]];
        } else if(x == 2 && y == 5) {
            [button setBackgroundColor:[UIColor redColor]]; 

        } else if(y == 0) {
            [button setBackgroundColor:[UIColor greenColor]]; 
        } else if(y == 1) {
            [button setBackgroundColor:[UIColor greenColor]]; 

        } else if(y == 2) {
            [button setBackgroundColor:[UIColor greenColor]]; 
        } else if(y == 3) {
            [button setBackgroundColor:[UIColor greenColor]]; 
        } else if(y == 4) {
            [button setBackgroundColor:[UIColor greenColor]]; 
        } else if(x == 1 && y == 6) {
            [button setBackgroundColor:[UIColor blueColor]]; 

        } else {


            //  [button setBackgroundColor:[UIColor grayColor]];
        }


        [button setTitle:[NSString stringWithFormat:@"W %d",currentTag] forState:UIControlStateNormal];
        button.frame = CGRectMake(80*x, 32*y, 80, 32); 
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [buttonView addSubview: button];

    }
  }

// Center the view which contains your buttons
CGPoint centerPoint = buttonView.center;
centerPoint.x = self.view.center.x;
buttonView.center = centerPoint;
[self.view addSubview:buttonView];    

}

RightNow このカレンダーに 12 か月を含めたいのですが、4 週間ごとにヘッダーとして 1 か月を追加しました

わからない CGMake でこのヘッダーを作成してループに入れるにはどうすればよいですか

助けてくれませんか

前もって感謝します!

4

2 に答える 2

1

探しているものを実現する最善の方法は、各行に 4 日間のセルと月名を含むヘッダー ビューを備えた UITableViewController を使用することです。あなたのアプローチはかなり強引であり、最終的には解決が非常に困難な多くのバグとパフォーマンスの低下をもたらします。

于 2012-07-30T08:01:38.027 に答える
0

uitableview にカスタムセルを使用し、必要なすべてのプロパティを設定することをお勧めします

于 2012-07-30T08:58:51.910 に答える