1、显示现在的时间
NSDate *now = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponets = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:now];
NSInteger nowHour = [dateComponets hour];
NSInteger nowMin = [dateComponets minute];
NSInteger nowSec = [dateComponets second];
[calendar release];
self.title = [NSString stringWithFormat:@"%02d:%02d:%02d",nowHour ,nowMin,nowSec];
2、打开WEB链接
->打开Google地图的操作
NSString *addressText = @"1 Queen st, Auckland, NZ";
addressText = [addressText stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSString *urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@",addressText];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
->打开百度链接
NSString *urlText = [NSString stringWithFormat:@"http://www.baidu.com"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];
3、用NSString怎么把UTF8转换成unicode
NSString *utf8Str = ...; //
NSString *unicodeStr = [NSString stringWithCString:[utf8Str UTF8String] encoding:NSUnicodeStringEncoding];
4、View自己调用自己的方法
[self performSelector:@selector(loginToNext) withObject:nil afterDelay:2];// loginToNext 为方法名, withObject为传入的参数(该参数只支持NSString、NSArray等) , afterDelay为 延迟的秒数.
5、显示网络活动状态指示符
就是载iPhone 左上部的状态栏显示的转动的图标指示有背景发生网络的活动。
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
或可以直接简化为:
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
6、图片动画:一个接一个地显示一系列的图象
NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"myImage1.png"], [UIImage imageNamed:@"myImage2.png"], [UIImage imageNamed:@"myImage3.png"], [UIImage imageNamed:@"myImage4.gif"], nil];
UIImageView *myAnimatedView = [UIImageView alloc];
[myAnimatedView initWithFrame:[self bounds]];
myAnimatedView.animationImages = myImages; //animationImages属性返回一个存放动画图片的数组
myAnimatedView.animationDuration = 0.25; //浏览整个图片一次所用的时间
myAnimatedView.animationRepeatCount = 0; // 0 = loops forever 动画重复次数
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];
[myAnimatedView release];
7、获取磁盘容量
#include <sys/param.h>
#include <sys/mount.h>
struct statfs buf;
float freeSpace = -1 ;
if (statfs ("/" ,&buf)>=0 )
{
freeSpace = (float )buf.f_bsize *buf.f_bfree ;// 可用磁 盘
}
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
struct statfs tStats;
statfs ([[paths lastObject ]cString ], &tStats);
float totalSpace = (float )(tStats.f_blocks *tStats.f_bsize );// 磁 盘总容量
float usedSpace = totalSpace - freeSpace; // 已用磁 盘 ;
NSLog (@"%f" ,usedSpace);
8、截取整个屏幕的操作
UIGraphicsBeginImageContextWithOptions(self .view .bounds .size , self .view .opaque , 0.0f );
[ self . view . layer renderInContext: UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imgData = UIImagePNGRepresentation (img);
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString *documentsDirectory = [paths objectAtIndex :0 ];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent :@"t.png" ];
[imgData writeToFile :filePath atomically :YES ];
以上部分有摘抄别人收集的信息,因文章篇幅有限,就不一一说出各位大侠博客或者文章的链接地址了。如有疑问者,请发站内邮件给我,我会及时的更新文章。谢谢~
//以小时为单位更新数据 NSUInteger Ratadata = ((NSUInteger) [[NSDate date] timeIntervalSince1970])/3600; int CurrentNum = Ratadata%[Array count]; //以天为单位更新数据 NSUInteger Ratadata = ((NSUInteger) [[NSDate date] timeIntervalSince1970])/(3600*24);