Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用objective-C中的CGMake将月份创建为标题_Objective C_Ios_Xcode - Fatal编程技术网

使用objective-C中的CGMake将月份创建为标题

使用objective-C中的CGMake将月份创建为标题,objective-c,ios,xcode,Objective C,Ios,Xcode,我通过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

我通过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];    

}
-(void)viewDidLoad
{
[超级视图下载];
//加载视图后执行任何其他设置。
int行=13,列=4;
UIView*buttonView=[[UIView alloc]initWithFrame:CGRectMake(0.f,0.f,80*列,32*行)];
int currentTag=0;
对于(int y=0;y
现在我想在这个日历中有12个月,每4周增加1个月作为标题

我不知道如何用CGMake创建这个标题并将其放入循环中

你能帮帮我吗


提前谢谢

实现所需功能的最佳方法是使用UITableViewController,每行有一个4天的单元格,并使用带有月份名称的标题视图。你的方法非常残忍,最终会给你带来很多很难解决的bug和低性能。

我建议你使用自定义单元格进行uitableview,并设置你需要的所有属性。

thansk但是如果我想像上面的代码那样做,你知道我该怎么做吗,因为我想让它像日历一样,但在表我只有一行,你可以设计表中的每一行容纳4个日期,然后你就可以得到日历网格。它现在的设计方式-我帮不了你。