macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

TextField

INDEX>SwiftUI > Views and Controls

テキストフィールド

Swift

struct TextField<Label> where Label : View

解説

A view that displays one or more lines of read-only text.

クラス

使用可能

参照

更新時のバージョン

関連記事(外部サイト)

例文


Swift

@State private var name = ""
    
    var body: some View {
        VStack {
            TextField("your name?", text: $name)
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .padding()
            Text("Hello, World!")
                       .frame(maxWidth: .infinity, maxHeight: .infinity)
            
        }
        
        
    }

Views and Controls

INDEX>SwiftUI > Views and Controls

Overview
ビューとコントロールは、アプリケーションのユーザーインターフェースの視覚的な構成要素です。
これらを使用して、アプリのコンテンツを画面に表示します。
ビューは、テキスト、画像、形状、カスタム図面、およびこれらすべての組み合わせを表します。
コントロールにより、ユーザーのプラットフォームとコンテキストに適応する一貫したAPIとの対話が可能になります。

視覚的な関係と階層を指定するコンテナーを使用してビューを結合します。
モディファイア(修飾子)と呼ばれるメソッドを使用して、組み込みビューおよびアプリ用に作成したビューの表示、動作、対話性をカスタマイズします。


ビューとコントロールにモディファイヤを適用して、次のことを行います。

ビューのサイズ、位置、および外観の属性を制御します。

タップ、ジェスチャー、その他のユーザー操作に応答します。

ドラッグアンドドロップ操作をサポートします。

アニメーションとトランジションをカスタマイズします。

スタイル設定とその他の環境データを設定します。

ビューとコントロールの使用方法の詳細については、ヒューマンインターフェイスガイドラインを参照してください。


トピック
必須

プロトコルビュー
SwiftUIビューを表すタイプ。


ビューの作成と結合
このチュートリアルでは、お気に入りの場所を発見して共有するためのiOSアプリであるランドマークの構築について説明します。 まず、ランドマークの詳細を示すビューを作成します。

UIコントロールの操作
ランドマークアプリでは、ユーザーは自分の個性を表現するプロファイルを作成できます。 ユーザーがプロフィールを変更できるようにするには、編集モードを追加して、設定画面をデザインします。

Text

struct Text
1行以上の読み取り専用テキストを表示するビュー。

struct TextField

TextField - Cocoa API解説(macOS/iOS)
編集可能なテキストインターフェイスを表示するコントロール

struct SecureField

ユーザーがセキュリティ入力を行うテキストコントロール

struct Font

An environment-dependent font.

Images

struct Image

A view that displays an environment-dependent image.

Buttons

struct Button

A control that performs an action when triggered.

struct NavigationLink
A button that triggers a navigation presentation when pressed.

struct MenuButton
A button that displays a menu containing a list of choices when pressed.

struct EditButton
A button that toggles the edit mode for the current edit scope.

struct PasteButton
A system button that triggers reading data from the pasteboard.

Value Selectors
struct Toggle
A control that toggles between on and off states.

struct Picker
A control for selecting from a set of mutually exclusive values.

struct DatePicker
A control for selecting an absolute date.

struct Slider
A control for selecting a value from a bounded linear range of values.

struct Stepper
A control used to perform semantic increment and decrement actions.

Supporting Types
struct ViewBuilder
A custom parameter attribute that constructs views from closures.

protocol ViewModifier
A modifier that you apply to a view or another view modifier, producing a different version of the original value.

SwiftUI

INDEX>SwiftUI

クラス

Essentials

SwiftUIでアプリを作成する方法を学ぶ
SwiftUIとXcodeを使用してアプリを作成する方法を学ぶには、一連のガイド付きチュートリアルを行ってください。


ユーザーインターフェース

ビューとコントロール
コンテンツを画面に表示し、ユーザーの操作を処理します。

ビューレイアウトと表示

スタック内のビューを組み合わせ、ビューのグループとリストを動的に生成し、ビューのプレゼンテーションと階層を定義します。

描画とアニメーション

色、形、影でビューを装飾し、ビューステート間のアニメーション化された遷移をカスタマイズします。

Framework Integration

Integrate SwiftUI views into existing apps, and embed AppKit, UIKit, and WatchKit views and controllers into SwiftUI view hierarchies.

Data and Events

State and Data Flow
Control and respond to the flow of data and changes within your app’s models.

Gestures

Define interactions from taps, clicks, and swipes to fine-grained gestures.

Previews in Xcode

Previews
Generate dynamic, interactive previews of your custom views.






maximumExtendedDynamicRangeColorComponentValue

INDEX>AppKit>NSScreen

拡張ダイナミックレンジ(EDR)値

Swift

open func canRepresent(_ displayGamut: NSDisplayGamut) -> Bool

解説

拡張ダイナミックレンジ(EDR)値

返り値

Swift

open var maximumExtendedDynamicRangeColorComponentValue: CGFloat { get }

引数

フレームワーク

ApplicationKit

クラス

NSScreen

使用可能

10.11-

参照

更新時のバージョン

OS X 10.14.5
Swift4.0

関連記事(外部サイト)

例文


Swift4.0

    @IBAction func function015(_ sender: Any) {
        let screenArray : [AnyObject] = NSScreen.screens
        for value in screenArray {
            print("value = \(Float(value.maximumExtendedDynamicRangeColorComponentValue)) ")
        }
    }

canRepresent

INDEX>AppKit>NSScreen

スクリーンでサポートされる色深度を返します

Swift

open func canRepresent(_ displayGamut: NSDisplayGamut) -> Bool

解説

ガモットマッピング可能かどうかを返します。

返り値

色深度の配列
Swift

open func canRepresent(_ displayGamut: NSDisplayGamut) -> Bool

引数

フレームワーク

ApplicationKit

クラス

NSScreen

使用可能

10.12

参照

更新時のバージョン

OS X 10.14.5
Swift4.0

関連記事(外部サイト)

developer.apple.com


例文


Swift4.0

@IBAction func function008(_ sender: Any) {
        let screenArray : [AnyObject] = NSScreen.screens
        for value in screenArray {
            let result : Bool = value.canRepresent(.sRGB)
            if (result){
                print("YES")
            }else{
                print("NO")
            }
        }
    }

colorWithGenericGamma22White:alpha:

INDEX>AppKit>NSColor

GenericGamma22カラースペース上で指定された白黒値とアルファ値でNSColorを作って返します。

Objective-C

+ (NSColor *)colorWithGenericGamma22White:(CGFloat)white
                                    alpha:(CGFloat)alpha

Swift

init(genericGamma22White white: CGFloat,
                   alpha alpha: CGFloat)

解説

GenericGamma22カラースペース上で指定された白黒値とアルファ値でNSColorを作って返します。

返り値

Objective-C

NSColor *

Swift

NSColor 

引数

Objective-C

(CGFloat)white

Swift

white: CGFloat

Objective-C

alpha:(CGFloat)alpha

Swift

alpha: CGFloat

フレームワーク

ApplicationKit

クラス

NSColor

使用可能

10.7

更新時のバージョン

OS X 10.11.4
Swift 2.0

関連記事

例文

Objective-C

Swift

//NSColor
    //colorWithGenericGamma22White:alpha:
    var aButton006 : NSButton?
    var aView006 : NSView?
    //実験用ビューのボタンを押した時に実行されるところ
    func viewAction006(sender : AnyObject?){
        //準備
        let aView   = aView006
        //準備ここまで
        
        aView?.lockFocus()
        let backgroundColor = NSColor(genericGamma22White: 0.6, alpha: 1.0)
        backgroundColor.setFill()
        NSRectFill(NSMakeRect(0, 20, 300.0, 178.0))
        aView?.unlockFocus()
        
    }
    @IBAction func function006(sender: AnyObject) {
        let aWindow : NSWindow
        = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300.0, 200.0),
            styleMask: NSTitledWindowMask
                | NSClosableWindowMask
                | NSMiniaturizableWindowMask
                | NSResizableWindowMask,
            backing: .Buffered,
            `defer`: false,
            screen: NSScreen.mainScreen())
        windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄
        aWindow.center()//ウインドウをスクリーンの中心に
        aWindow.title = "View アクション"//タイトル設定
        //ボタン
        let theButton : NSButton = NSButton(frame: NSMakeRect(100.0, 10.0, 100.0, 30.0))
        theButton.title = "Color!"
        theButton.bezelStyle = NSBezelStyle.RoundedBezelStyle
        theButton.action = Selector("viewAction006:")
        theButton.target = self
        
        aWindow.contentView!.addSubview(theButton)
        //ビュー
        let theView : NSView = NSView(frame: NSMakeRect(0.0, 30.0, 300.0, 180.0))
        theView.wantsLayer = true
        aWindow.contentView!.addSubview(theView)
        
        //実験ウインドウにUIパーツを渡す
        self.aButton006 = theButton    //ボタン
        self.aView006 = theView        //テストビュー
        
        aWindow.orderFront(self)//前面に
        aWindow.makeKeyAndOrderFront(self)//表示
    }

f:id:jjj777:20160618140020p:plain