0
0

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.

Xcode8でmacOS向けのアプリでのLabelの使い方?

Posted at

この記事では[xcode8.3.3],[swift3.1]を使っています。
まとめが一番後ろにあるのでたぶんそこだけ見れば大丈夫です。

想像してたやつ

iOSViewController.swift
import UIKit

class iOSViewController: UIViewController {
    @IBOutlet var label:UILabel!
    count:Int = 0
    override func viewDidLoad() {
        super.viewDidLoad()
        label.text = String(count)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

##書いたやつ

ViewController.swift
import Cocoa

class ViewController: NSViewController {
    @IBOutlet var label: NSTextField!
    var count:Int = 0
    override func viewDidLoad() {
        super.viewDidLoad()
        label.intValue = Int32(count)
    }
    override var representedObject: Any? {
        didSet {
        }
    }
}

#違ったところまとめ

  • UILabel -> NSTextField
  • .textではなく.{型(ex. Int,String,...)}Valueと書く
  • ただしintValueで指定される型はInt32
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?