[Xcode]NSLocalizedStringでローカライズ

iPhoneアプリをローカライズ(多言語対応)するときNSLocalizedStringを使うと便利です。
1.まずResourcesなど右クリックして「New File」をクリック
2.ResourceのStrings Fileを選択
3.ファイル名:Localizable.stringsで保存
4.Localizable.stringsを選択してXcodeの右カラムのLocalizationの「+」から言語を選択します。
5.各言語のLocalizable.stringsには下記のようにテキストを設定します。

Localizable.strings(English)

hogeText="hoge";

Localizable.strings(Japanese)

hogeText="ほげ";

6.使うときはこう

NSString*s=NSLocalizedString(@"hogeText", nil);

[objective-c]UIActionSheet

アクションシートの出し方です。
アクションシートというのはこういうやつです。

まずデリゲートの設定をします。

@interface HogeViewController : UIViewController <UIActionSheetDelegate> {

そしてHogeViewController.mに下記コードを記述してsetActionSheetで実行します。

//アクションシートのボタンを押した直後
-(void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    NSLog(@"clickedButtonAtIndex %d",buttonIndex);
    switch (buttonIndex) {
        case 0://選択1
            
            break;
        case 1://選択2
            
            break;
        case 2://選択3
            
            break;
        case 3://キャンセル
            
            break;
        default:
            break;
    }
}
//ボタンを押してアクションシートが下へ消えたとき
-(void)actionSheet:(UIActionSheet*)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
    NSLog(@"didDismissWithButtonIndex %d",buttonIndex);
}
-(void)setActionSheet{
    UIActionSheet *as = [[UIActionSheet alloc] init];
    as.delegate=self;
    as.title=@"アクションシート";
    [as addButtonWithTitle:@"選択1"];
    [as addButtonWithTitle:@"選択2"];
    [as addButtonWithTitle:@"選択3"];
    as.cancelButtonIndex=3;
    [as showInView:self.view.window];
    [as release];
}

[objective-c]UIViewで表示されている状態をUIImageにする

UIViewに表示した状態をUIImageにすることが出来ます。
UIImageにすればカメラロールに保存したり、SNSにアップロード出来ます。

- (UIImage *)screenImage:(UIView *)view{
    UIImage *screenImage;
    UIGraphicsBeginImageContext(view.frame.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    screenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImage;
}

[objective-c]画像(UIImage)をpngでカメラロールに保存する

UIImageをpngで保存するときは、普通に保存する処理に2行ほどコードを追加します。
下記コードではsavePhotoPngメソッドにUIImageを渡せばpngで保存されます。

-(void)savePhotoPng:(UIImage*)orizinalSizeImage{
    NSData *imageData = UIImagePNGRepresentation(orizinalSizeImage);
    UIImage *pngimage = [UIImage imageWithData:imageData];
    
    UIImageWriteToSavedPhotosAlbum(pngimage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}

//写真保存後にコールバックされる
-(void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo{
    if(error){//エラーのとき
        
    }else{//保存できたとき
        
    }

[iPhone Apps]BurnedPhoto(焼フォト,PhotoBrûlé)

iPhoneアプリ「焼フォト」をリリースしました。
焼フォトは写真を火で焼いたような写真に加工するアプリです。
Twitter,Facebookに対応しており、作った写真をすぐにアップロードすることが出来ます。
焼き加減、コントラスト、ガンマの度合いを調整して自分好みの設定で写真を加工しましょう。

主な機能
■撮った写真または保存されている写真を火で焼いたような写真に加工できます。
■焼き加減を調整できます。
■コントラストを調整できます。
■ガンマを調整できます。
■写真をTwitterへアップロードできます。
■写真をFacebookへアップロードできます。
■写真を使用中のiPhone,iPodへ保存できます。(写真はpng形式で保存されます)

BurnedPhoto is photo retouch App.
You can convert any photo to an image burned.
And You can upload photos to Twitter,Facebook.
Enable to adjust the FirePower,Contrast And Gamma.

Features
■Enable to convert any photo to an image burned.
■Enable to adjust Fire Power.
■Enable to adjust Contrast.
■Enable to adjust Gamma.
■Enable to upload photo to Twitter.
■Enable to upload photo to Facebook.
■Enable to save photo to your device.(saved photo is png format)

PhotoBrûlé est retouche photo App.
Vous pouvez convertir n’importe quelle photo pour une image brûlée.
Et vous pouvez télécharger des photos vers Twitter, Facebook.
Permettent de régler la puissance de feu, contraste et le gamma.

Features
■ Permettre de convertir n’importe quelle photo pour une image brûlée.
■ Permettre à ajuster puissance de feu.
■ Permettre à régler le contraste.
■ Activer pour régler Gamma.
■ Permettre à charger une photo sur Twitter.
■ Permettre à charger une photo sur Facebook.
■ Activer pour sauvegarder la photo sur votre appareil. (Photo est enregistrée au format png)


焼フォト
焼フォト


BurnedPhoto

PhotoBrûlé

焼フォト焼フォト

焼フォト焼フォト

[objective-c]画像(UIImage)をカメラロールに保存する

UIImageをカメラロールに保存する方法はこうします。
下記コードのsavePhotoを実行したらすぐに保存が開始されますが、
保存が終わるまで時間が空くので、その間はローディングのぐるぐるみたいのを出しておくと良いでしょう。

-(void)savePhoto:(UIImage*)orizinalSizeImage{
    UIImageWriteToSavedPhotosAlbum(orizinalSizeImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
//写真保存後にコールバックされる
-(void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo{
    if(error){//エラーのとき
        
    }else{//保存できたとき
        
    }
}

[iPhone Apps]OldFilmPhoto(古映画フォト)

iPhoneアプリ「古映画フォト」をリリースしました。
古映画フォトは写真を昔のフィルム映画のような写真に加工するアプリです。
Twitter,Facebookに対応しており、作った写真をすぐにアップロードすることが出来ます。
彩度、ぼかしの度合いを調整して自分好みの設定で写真を加工しましょう。

主な機能
■撮った写真または保存されている写真を昔のフィルム映画のような写真に加工できます。
■彩度を調整できます。
■セピア具合を調整できます。
■ぼかしを調整できます。
■写真をTwitterへアップロードできます。
■写真をFacebookへアップロードできます。
■写真を使用中のiPhone,iPodへ保存できます。

OldFilmPhoto is photo retouch App.
Enable to convert the photo that look like old film.
You can upload photos to Twitter,Facebook.
Enable to adjust the saturation, sepia and blurring.

Features
■Enable to convert the photo that look like old film.
■Enable to adjust saturation.
■Enable to adjust sepia.
■Enable to adjust blurring.
■Enable to upload photo to Twitter.
■Enable to upload photo to Facebook.
■Enable to save photo to your device.


古映画フォト
古映画フォト


OldFilmPhoto

古映画フォト古映画フォト

古映画フォト古映画フォト

[objective-c]Camera

iPhone Apps「魚眼フォト」などで使っている方法です。

カメラ、アルバムから画像を取得する時こうします。
まずデリゲートメソッド使用のためのの設定
下記の例だと「CameraViewController.h」にこれを記述する。

@protocol UIImagePickerControllerDelegate;
@protocol UINavigationControllerDelegate;
@interface CameraViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>

そして、なんやかんやの処理を「CameraViewController.m」へ

//カメラ、アルバムから画像をもらった時
-(void)whenCameraDone:(UIImage*)omg{
    
}

//アラートでok押したとき
-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (alertno==1) {//NoCamera
        [self whenCameraDone:nil];
    }else if(alertno==2){//NoAlbum
        [self whenCameraDone:nil];
    }
}

//カメラが使えないときのアラート
-(void)alertNoCamera{
    alertno=1;
    UIAlertView *al=[[UIAlertView alloc]
                     initWithTitle:NSLocalizedString(@"NoCamera", nil)
                     message:nil
                     delegate:self
                     cancelButtonTitle:nil
                     otherButtonTitles:@"OK",nil];
    [al show];
    [al release];
}
-(void)takePhoto{
    UIImagePickerControllerSourceType pst=UIImagePickerControllerSourceTypeCamera;
    if([UIImagePickerController isSourceTypeAvailable:pst]){
        UIImagePickerController *pic=[[UIImagePickerController alloc]init];
        pic.delegate=self;
        pic.sourceType=pst;
        [self presentModalViewController:pic animated:YES];
        [pic release];
    }else{
        //カメラが使えないとき
        [self alertNoCamera];
    }
}

//撮影,画像選択>使用時
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    UIImage *originalImage=[info objectForKey:UIImagePickerControllerOriginalImage];
    [self dismissModalViewControllerAnimated:YES];
    [self whenCameraDone:originalImage];
}
//撮影キャンセル時
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    //[self dismissViewControllerAnimated:YES];
    [self dismissModalViewControllerAnimated:YES];
    [self whenCameraDone:nil];
}

//Albumが使えないときのアラート
-(void)alertNoAlbum{
    alertno=2;
    UIAlertView *al=[[UIAlertView alloc]
                     initWithTitle:NSLocalizedString(@"NoAlbum", nil)
                     message:nil
                     delegate:self
                     cancelButtonTitle:nil
                     otherButtonTitles:@"OK",nil];
    [al show];
    [al release];
}
-(void)openAlbum{
    UIImagePickerControllerSourceType pst=UIImagePickerControllerSourceTypePhotoLibrary;
    if([UIImagePickerController isSourceTypeAvailable:pst]){
        UIImagePickerController *pic=[[UIImagePickerController alloc]init];
        pic.delegate=self;
        pic.sourceType=pst;
        [self presentModalViewController:pic animated:YES];
        [pic release];
    }else{
        //Albumが使えないとき
        [self alertNoAlbum];
    }
}

で使うときは下記のようにメソッドを実行する。

//カメラ
[self takePhoto];

//アルバム
[self openAlbum];

結構大変ですね。

[cocos2d]CCLabelTTF

cocos2dで文字列を表示させたい時はCCLabelTTFを使います。
FlashのTextFieldみたいなものです。
使い方はこう

CCLabelTTF*sizelabel=[CCLabelTTF labelWithString:@"ImageSize" fontName:@"HiraKakuProN-W6" fontSize:12];
[sizelabel setAnchorPoint:ccp(0.0,1.0)];
sizelabel.positionInPixels=ccp(100.0,200.0);
[self addChild:sizelabel z:19];

[sizelabel setString:@"hoge"];

[objective-c]画像(UIImage)をリサイズする

iPhone Apps「魚眼フォト」などで使っている方法です。
いいと思います。

- (UIImage*)resizedImage:(UIImage *)img size:(CGSize)size{
    CGFloat widthRatio  = size.width  / img.size.width;
    CGFloat heightRatio = size.height / img.size.height;
    if (widthRatio==1.0 && heightRatio==1.0) {
        return img;
    }
    CGSize resizedSize = CGSizeMake(img.size.width*widthRatio, img.size.height*heightRatio);
    
    UIGraphicsBeginImageContext(resizedSize);
    
    [img drawInRect:CGRectMake(0, 0, (int)resizedSize.width, (int)resizedSize.height)];
    UIImage* resizedImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return resizedImage;
}
//元の画像
UIImage*img=[UIImage imageNamed:@"hoge.png"];
CGRect*rect=CGRectMake(0.0, 0.0, 10.0, 20.0);

//リサイズした画像
UIImage*resizedImage=[self resizedImage:img rect:rect];