13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ビュー、サブビューの操作、画像表示

Posted at

アプリ画面

やったこと

  • ビュー、サブビュー、シーンについて確認
  • ビューをプログラムから生成
  • ボタンでビューを削除
  • 画像を表示(GUIのみ)

コード

ViewController.swift

class ViewController: UIViewController {
    
    // 削除対象のラベル
    @IBOutlet var TargetViewStrong: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        // プログラムでラベルを追加
        var myLab:UILabel = UILabel()
        myLab.text = "いいね!ラベル生成"
        // 中央寄せ
        myLab.textAlignment = NSTextAlignment.Center
        myLab.textColor = UIColor.greenColor()
        myLab.backgroundColor = UIColor.orangeColor()
        // 24ポイントの太字にする
        myLab.font = UIFont.boldSystemFontOfSize(24)
        // 座標とサイズを指定
        myLab.frame = CGRectMake(20, 100, 350, 30)
        
        // ビューに追加
        self.view.addSubview(myLab)
    }

    // ビュー削除
    @IBAction func RemoveLabelView(sender: UIButton) {
        if (self.TargetViewStrong.isDescendantOfView(self.view)) {
            // トップのサブビューであれば削除
            self.TargetViewStrong.removeFromSuperview()
            
            // 非表示にするコード
            //self.TargetViewStrong.hidden = true
        } else {
            // 追加
            self.view.addSubview(self.TargetViewStrong)
        }
        
        // .superviewで親ビューをコンソール確認
        print(self.TargetViewStrong.superview)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

コメント

DB操作とか早くしたいのだけど、つまらない細かい部分でなかなか進まない。

13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?