开发小技巧

1.设置View阴影

button.layer.shadowOffset = CGSizeMake(0, 5); //设置阴影的偏移量
button.layer.shadowRadius = 10.0;  //设置阴影的半径
button.layer.shadowColor = [UIColor blackColor].CGColor; //设置阴影的颜色为黑色
button.layer.shadowOpacity = 0.6; //设置阴影的不透明度

 

2.计算文字长度

CGSize size = [contentString sizeWithFont:[UIFont systemFontOfSize:14.0]

                                     constrainedToSize:CGSizeMake(310, 2000)

                                           lineBreakMode:UILineBreakModeWordWrap];

 

3.计算俩个纬度之间的距离

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 = drivingtransit, or walking

comgooglemaps://?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

猜你喜欢

转载自yangping-account.iteye.com/blog/1882645