Wednesday, March 20, 2013

スクリーンショットからステータスバー削除

MacPortsでImageMagickインストール
$ sudo port install ImageMagick

convertで削除
$ convert -crop 640x920+0+40 input.png output.png


参考

warning: Attribute Unavailable: Freeform Size simulated metrics are not available prior to Xcode 4.2.

NIBの設定を変える。
[Interface Builder Document]→[Development]を変える。


参考

Xcode4.6スタティックライブラリ

ライブラリ

Cocoa Touch Static Libraryでプロジェクトを作成
Build Settingsで
・Skip Install→YES
・Other Linker Flags→-ObjC
Build Phasesで
・Copy Filesに.hファイルを追加

使う側のプロジェクト

ライブラリの.xcodeprojをプロジェクトに入れるか同じワークスペースに入れる
Linked Frameworks and Librariesにライブラリの.aを追加
Build Settingsで
・Other Linker Flags→-ObjC
・Always Search User Paths→YES
・Header Search Path→$(BUILT_PRODUCTS_DIR)
・User Header Search Paths→ライブラリの絶対パスを指定

Tuesday, March 19, 2013

navigationBarとtoolBarを透明にする

navigationbar, toolbarをUIBarStyleBlackTranslucent以外で透明にする方法

barのbackgroundimageに透明なimageを設定
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:0.0f alpha:0.8f]] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.toolBar setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithWhite:0.0f alpha:0.8f]] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsDefault];

透明なimageはどう生成してもいいんですが、ここでは以下のカテゴリで作成している
#import "UIImage+Color.h"

@implementation UIImage (Color)

+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
        
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
        
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
        
    return image;
}

@end

Picstasy ver1.0.0

2つ目のアプリPicstasyをリリースしました
https://itunes.apple.com/us/app/picstasy/id617328186?l=ja&ls=1&mt=8

Pixiv専用の画像ビューアです
アプリといったらやっぱり画像ビューアでしょ!?(謎)ということで作成しました
はっきりいって、画像の原寸サイズ表示やページありのイラストの表示とか
いろいろやってないので機能としてはいまいちです
申請は通ったので、これをもとにして作り直すかなぁといったところです。

言い訳乙

Friday, March 15, 2013

UIScrollViewでnavigationBarやtoolBarをスクロール範囲に被らないように透けさせて配置

タイトルが長い

どういうことかと言うと、普通にnavigationBarとtoolBarをUIBarStyleBlackTranslucentに設定して、
UIScrollViewをself.viewに突っ込むだけだと、
スクロール範囲がnavigationBarとtoolBarに被ってしまって見栄えが非常に良くない
(例えば一番下までスクロールしても、UIScrollViewのcontentがtoolBarに被ってしまう)

これが例えば、UITableViewContollerを使ったりすると、
tableViewは透けるのにスクロール範囲はnavigationBar, toolBarに被らないように
よろしくやってくれたりする

それをUIScrollViewでやりたい
上記を実現する為に、
  1. UIScrollViewのcontentの余白をbarのheight分縮める
  2. UIScrollViewのスクロールバーの余白?もbarのheight分縮める
コードで書くと、以下のような感じ

// 対象のscrollView
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
                 :
- (void)viewDidLoad
{
 [super viewDidLoad];

 // barを透明に
 self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
 self.navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent;

 UIEdgeInsets insets;
 // contentを縮める
 insets= self.scrollView.contentInset;
 insets.top = self.navigationController.navigationBar.frame.size.height;
 insets.bottom = self.navigationController.toolbar.frame.size.height;
 self.scrollView.contentInset = insets;
 // スクロールバーの範囲を縮める
 insets = self.scrollView.scrollIndicatorInsets;
 insets.top = self.navigationController.navigationBar.frame.size.height;
 insets.bottom = self.navigationController.toolbar.frame.size.height;
 self.scrollView.scrollIndicatorInsets = insets;
 
 // そのままだと初期位置がnavigationBarに被るので下にずらす
 CGPoint point = self.scrollView.contentOffset;
 point.y = -1*self.scrollView.contentInset.top;
 self.scrollView.contentOffset = point;
}

これでいろいろ透けさせることができそう(意味深)


参考

Friday, March 8, 2013

sshのknown_hostsでwarning

サーバが変わった場合に以下のような警告が出ることがある。
user@host01:~$ ssh user@host02
Warning: the ECDSA host key for 'host02' differs from the key for the IP address 'xxx.xxx.xxx.xxx'
Offending key for IP in /home/user/.ssh/known_hosts:199
Matching host key in /home/user/.ssh/known_hosts:208
Are you sure you want to continue connecting (yes/no)? 
上記の例だと、/home/user/.ssh/known_hosts の199行目を削除して保存すればおk