iPhone基础学习例子

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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值