Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

アプリ画面

やったこと

  • ビュー、サブビュー、シーンについて確認
  • ビューをプログラムから生成
  • ボタンでビューを削除
  • 画像を表示(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操作とか早くしたいのだけど、つまらない細かい部分でなかなか進まない。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした