macOS/iOS API解説

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

目次

imageAlignment

フレームでの画像の位置を返します

解説

フレームでの画像の位置を返します。
【NSImageAlignment】配置
● NSImageAlignLeft 左寄せ
● NSImageAlignRight 右寄せ
● NSImageAlignCenter 中心寄せ
● NSImageAlignTop 上寄せ
● NSImageAlignBottom 下寄せ
● NSImageAlignTopLeft 左上寄せ
● NSImageAlignTopRight 右上寄せ
● NSImageAlignBottomLeft 左下寄せ
● NSImageAlignBottomRight 右下寄せ

返り値

( NSImageAlignment )

画像の位置

引数

フレームワーク

ApplicationKit

クラス

NSImageView

Instance Methods

使用可能

10.0

参照

例文

#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{
    //開けるファイル拡張子の配列
    NSArray      *imgTypes    = [ NSArray arrayWithObject : @"tiff" ];
    //OpenPanelを作る
    NSOpenPanel  *opImage       = [ NSOpenPanel openPanel ];
    //Imageを作る
    NSImage      *img;
    
      NSImage      *Copyimg;

    //OpenPanelの結果のボタン番号
    int		  opRet;
     
        //OpenPanelでファイル選択   
    opRet = [ opImage runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
                                     file : @"Pictures" //どのどのファイルを選択しておくか
                                    types : imgTypes ];//選べるファイルタイプ

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
        //NSImageを作ってファイルから読み込む
        img = [ [ NSImage alloc ] 
                          initWithContentsOfFile: [ opImage filename ] ];
        //レシーバimage(NSImageView)にimgをセットする
        [image1 setImage : img ];
        
        Copyimg =  [ NSImage alloc ];
        Copyimg = [image1 image];
        [image1 setImageAlignment : NSImageAlignTop ];  
        [image2 setImage : Copyimg ];
        [image2 setImageAlignment : [image1 imageAlignment] ];                          
    }
}

@end