Webエンジニアの備忘録

およそ自己の作業メモとして残しております。

iPhoneアプリ開発、ViewControllerあたりを写経する

かなり真面目にマニュアルに従って開発作法を学んできたが、Xcodeの作法のところはCSSのパラメータ暗記と通ずるところがあるなあ、という私見を抱いた。

なにが面倒というと、やっぱり覚えなきゃならない呪文が多い。これはXcodeフレームワークを提供しているから仕方ないんだけど、この手の勉強方法は覚えるしか無いんだな、と再確認。

 

ちょっと忘れそうになってきたので、中途だが備忘録を残しておく。

 

    // オブジェクト
    UIView *customView = [[UIView alloc] init];
    customView.frame = CGRectMake(0.0, 0.0, 200.0, 200.0);
    customView.center = CGPointMake(160.0, 160.0);
    customView.backgroundColor = [UIColor redColor];
    customView.hidden = NO;
    [self.view addSubview:customView];

 

    // 画像
    UIImageView *customImage = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
    customImage.hidden = NO;
    customImage.image = [UIImage imageNamed:@"sample.png"];
    [self.view addSubview:customImage];

 

    // ラベル
    UILabel * customLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 40)];
    customLabel.font = [UIFont fontWithName:@"HiraKakuProN-W6" size:18];
    customLabel.text = @"ラベルエリア";
    customLabel.shadowColor = [UIColor grayColor];
    customLabel.shadowOffset = CGSizeMake(2, 2);
    [self.view addSubview:customLabel];

 

    // ボタン
    UIButton *customButton1 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
    customButton1.frame = CGRectMake(40, 80, 240, 40);
    [customButton1 setTitle:@"ここを押してください" forState:UIControlStateNormal];
    [customButton1 addTarget:selfaction:@selector(action) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:customButton1];

 

    // ボタン(画像)
    UIButton *customButton2 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
    customButton2.frame = CGRectMake(120, 160, 80, 80);
    [customButton2 setImage:[UIImageimageNamed:@"button1.png"] forState:UIControlStateNormal];
    [customButton2 setImage:[UIImageimageNamed:@"button2.png"] forState:UIControlStateHighlighted];
    [customButton2 addTarget:selfaction:@selector(action) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:customButton2];

 

    // スイッチ
    UISwitch *customSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(120, 240, 0, 0)];
    customSwitch.on = NO;
    [customSwitch addTarget:selfaction:@selector(action2:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:customSwitch];

細かいオプションの選択肢もあったけど、ひとまず動くやつをメモっておく。