iPhone SDK示例代码

这篇博客是针对初学者的iPhone SDK指南,涵盖了从写Log、图片显示到复杂的动画、网络状态检测和线程管理等多个方面。通过实例代码,讲解了字符串转换、正则表达式、定时器使用等核心概念,并探讨了如何处理应用程序崩溃日志和进行性能分析。
摘要由CSDN通过智能技术生成

Phone SDK新手必读

写Log

在Xcode里,点菜单Run > Console 就可以看到NSLog的记录.
NSLog(@"log: %@ ", myString); NSLog(@"log: %f ", myFloat); NSLog(@"log: %i ", myInt);

图片显示

不需要UI资源绑定,在屏幕任意处显示图片。 下面的代码可以被用到任意 View 里面。
CGRect myImageRect = CGRectMake(0.0f, 0.0f, 320.0f, 109.0f); UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect]; [myImage setImage:[UIImage imageNamed:@"myImage.png"]]; myImage.opaque = YES; // explicitly opaque for performance [self.view addSubview:myImage]; [myImage release];

应用程序边框大小

我们应该使用" bounds "来获得应用程序边框。不是用" applicationFrame "。" applicationFrame "还包含了一个20像素的status bar。除非我们需要那额外的20像素的status bar。

Web view

UIWebView类的调用.
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0); UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame]; [webView setBackgroundColor:[UIColor whiteColor]]; NSString *urlAddress = @"http://www.google.com"; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webView loadRequest:requestObj]; [self addSubview:webView]; [webView release];

显示网络激活状态图标

在iPhone的状态栏的左上方显示的一个icon假如在旋转的话,那就说明现在网络正在被使用。
UIApplication* app = [UIApplication sharedApplication]; app.networkActivityIndicatorVisible = YES; // to stop it, set this to NO

Animation: 一组图片

连续的显示一组图片
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; myAnimatedView.animationDuration = 0.25; // seconds myAnimatedView.animationRepeatCount = 0; // 0 = loops forever [myAnimatedView startAni
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值