Cocoa API解説(macOS/iOS)

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。

目次

Views and Controls

INDEX>SwiftUI > Views and Controls

Overview
Views and controls are the visual building blocks of your app’s user interface. Use them to present your app’s content onscreen. Views represent text, images, shapes, custom drawings, and compositions of any and all of these together. Controls enable user interaction with consistent APIs that adapt to their platform and context.

Combine views using containers that specify their visual relationships and hierarchy. Use methods called modifiers to customize the display, behavior, and interactivity of built-in views and those you create for your app.

You apply modifiers to views and controls to:

Control the size, position, and appearance attributes of the view.

Respond to taps, gestures, and other user interactions.

Support drag and drop operations.

Customize animations and transitions.

Set style preferences and other environment data.

For additional information about how to use views and controls, see Human Interface Guidelines.

Topics
Essentials
protocol View
A type that represents a SwiftUI view.

Creating and Combining Views
This tutorial guides you through building Landmarks — an iOS app for discovering and sharing the places you love. You’ll start by building the view that shows a landmark’s details.

Working with UI Controls
In the Landmarks app, users can create a profile to express their personality. To give users the ability to change their profile, you’ll add an edit mode and design the preferences screen.

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

struct TextField
A control that displays an editable text interface.

struct SecureField
A control into which the user securely enters private text.

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

Learn to Make Apps with SwiftUI
Follow a series of guided tutorials to learn to make apps using SwiftUI and Xcode.

User Interface

Views and Controls
Present your content onscreen and handle user interactions.

View Layout and Presentation

Combine views in stacks, generate groups and lists of views dynamically, and define view presentations and hierarchy.

Drawing and Animation

Enhance your views with colors, shapes, and shadows, and customize animated transitions between view states.

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

colorWithSRGBRed:green:blue:alpha:

INDEX>AppKit>NSColor

解説

返り値

Objective-C

Swift


フレームワーク

ApplicationKit

クラス

NSColor

使用可能

10.0

更新時のバージョン

OS X 10.11.4
Swift 2.0

参照

関連記事