開発テクニック

2962 ワード

1.Viewシャドウの設定
button.layer.shadowOffset = CGSizeMake(0, 5);//シャドウのオフセット量を設定します.layer.shadowRadius = 10.0;//影の半径を設定するlayer.shadowColor = [UIColor blackColor].CGColor;//シャドウの色を黒に設定します.layer.shadowOpacity = 0.6;//シャドウの不透明度の設定
 
2.文字長の計算
CGSize size = [contentString sizeWithFont:[UIFont systemFontOfSize:14.0]
                                     constrainedToSize:CGSizeMake(310, 2000)
                                           lineBreakMode:UILineBreakModeWordWrap];
 
3.2つの緯度間の距離を計算する
CLLocation * newLocation = [[CLLocation alloc]initWithLatitude:32.0206410 longitude:118.7889040]; NSString *km = [NSString stringWithFormat:@"%0.2f km",[[current location] distanceFromLocation:newLocation]/1000]
 
4.コード統計
find . "("-name "*.m"-or -name "*.mm"-or -name "*.cpp"-or -name "*.c"-or -name "*.xib"-or -name "*.plist"-or -name "*.pch"-or -name "*.h"-or -name "*.rss"")"-print | xargs wc -l 
 
5.計算間隔
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
 unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit |NSMinuteCalendarUnit| NSSecondCalendarUnit;
NSDateComponents *comps = [gregorian components:unitFlags fromDate:commentDate toDate:[NSDate date] options:0];
 
int month = [comps month];
int day = [comps day];
int hour = [comps hour];
int minute = [comps minute];
int second = [comps second];
       
if (month == 0 && day == 0 && hour == 0 && minute == 0 && second >= 0) {
commentDateString=[NSString stringWithFormat:@"%d秒前",second];
}else if (month == 0 && day == 0 && hour == 0 && minute >0){
commentDateString=[NSString stringWithFormat:@"%d分前",minute];
}else if (month == 0 && day == 0 && hour > 0){
commentDateString=[NSString stringWithFormat:@"%d時間前",hour];
}else if (month == 0 && day > 0){
commentDateString=[NSString stringWithFormat:@"%d天前",day];
 }
6.地図サービスを呼び出す
Googleナビゲーションdirectionsmode=driving,transit,or walkingcomgooglemaps://?saddr=北京&daddr=上海&directionsmode=driving
アップルナビゲーション
http://maps.apple.com/?saddr=北京&daddr=上海
緯度変換アドレス
http://maps.googleapis.com/maps/api/geocode/json?latlng=31.548182,120.241914&sensor=true&language=zh
7.Libraryフォルダの表示
defaults write com.apple.finder AppleShowAllFiles YES 
chflags nohidden $HOME/Library
8.XML解析ライブラリのインポート
libxml2.dylib
Header Search Paths =/usr/include/libxml2
Other Linker Flags = -lxml2
9.Arcで非Arcクラスライブラリを使用
-fno-objc-arc
10.App Infomation
http://itunes.apple.com/lookup?id=683790165