2013年4月24日水曜日

012-NSString(Foundation)

NSStringクラス

生成
NSString* 変数名 = @"文字列";

NSString変数名 = [[NSString alloc] initWithString:@"文字列"];

NSString* 変数名 = [NSString stringWithFormat:@"文字列"];

こんな感じで生成できます。


■指定した文字かの判定

NSString* sText = @"比較先";
[sText isEqualToString:@"比較もと"];

結果はBooleanで返されます。
今回の出力結果は偽になります。

■指定した文字列ではじまっているかの判定

NSString* sText = @"比較先";
[sText hasPrefix:@"比較"];

結果はBooleanで返されます。
今回の出力結果は真になります。

■指定した文字列で終わっているかの判定

NSString* sText = @"比較先";
[sText hasSuffix:@"較先"];


結果はBooleanで返されます。
今回の出力結果は真になります。

■文字列の後ろから返す

NSString* sText = @"比較先";
[sText substringFromIndex:int型];

指定した文字列から最後までの文字列を返します。


[sText substringFromIndex: sText.length - 1]

こんな感じにすると、sTextの最後の文字列を返します。
-1を-2にすると、後ろから2文字目を全て返します。。。


2013年4月7日日曜日

010-ピッカーの表示(UIPickerView)

ピッカーの使い方に関して。。

iPhone使ってる人はピッカーで何の事かわかるのすかね??

ドラムロールから、任意のステータスを選択するあれです。

では、例文です。

■サンプルソース

h.ファイル


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIPickerViewDelegate,UIPickerViewDataSource>{
    NSArray*       aItemList;
    UIPickerView*  oPicker;
    UILabel*       oLabel;
}

@end


m.ファイル

#import "ViewController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [self showPicker];
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)showPicker {
    //ピッカーにアイテムを格納
    aItemList = [[NSMutableArray alloc] initWithObjects:@"リンゴ",@"バナナ",@"マンゴー",@"パパイア", @"ドリアン",nil];
    
    // ピッカーの生成
    oPicker = [[UIPickerView alloc] init];
    //中央に表示
    oPicker.center = self.view.center;
    oPicker.showsSelectionIndicator = YES;
    oPicker.delegate = self;
    oPicker.dataSource = self;
    //画面に追加
    [self.view addSubview:oPicker];
    
    //ラベルの生成
    oLabel = [[UILabel alloc] init];
    oLabel.frame = CGRectMake(0,0,200,50);
    oLabel.text  =@"何が選ばれるのだろう";
    //画面に追加
    [self.view addSubview:oLabel];

}

//区切りの数(コンポーネント)
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

//コンポーネントの行数を返す
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return [aItemList count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    return [aItemList objectAtIndex:row];
}

//選択完了時に呼ばれる
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    //選択行を返す
    NSInteger id = [pickerView selectedRowInComponent:0];
    oLabel.text  = [NSString stringWithFormat:@"%@",aItemList[id]];
}

@end


■実行結果




実行すると、
選択した項目が文字列で出力できていることが確認できると思います。

hファイルでデリゲートの準備をし忘れないように!
@interface ViewController : UIViewController <UIPickerViewDelegate,UIPickerViewDataSource>{

mファイルの生成時にデリゲートが呼ばれます。
oPicker.delegate = self;
oPicker.dataSource = self;


//選択完了時に呼ばれる
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
この関数を作成すると、選択している項目を取得できます。


正直UIPickerViewはコードで全部書くのはしんどかったです。
はい。

2013年4月6日土曜日

アイコン画像・起動画面(App Icons, Launch Images)

iPhoneアプリに必要な画像のサイズを適当にメモっておきます。
リリース前にはそろえましょう!!

■アイコン(App Icons)
・サイズ(単位はpx)
  57×57
  114×114  Retina
・保存形式
  png

■起動画面(Launch Images)

・サイズ(単位はpx)
  320×480
  640×960   Retina3.5
  640×1136 Retina3.5
・保存形式
  png