Corona中文站

强大、易学的跨平台(iOS/Android)开发框架。QQ群1:74390406(满) 群2:221929599

导航

iphone从web服务器获取图片并显示在视图上
新建一个ViewBased项目名xxx,将以下代码替换掉xxxViewController的viewDidLoad方法

- (void)viewDidLoad

{

NSURL * imageURL = [NSURL
URLWithString:@"http://ftp.javaeye.com/aywy7vd/javaeye/banner.jpg"];

NSData * imageData = [NSData dataWithContentsOfURL:imageURL];

UIImage * image = [UIImage imageWithData:imageData];
...
iphone如何将图片保存到相册中
将图片保存在一个数组中,通过UIImageWriteToSavedPhotosAlbum进行保存
//in the .h file put:
NSMutableArray
*myPhotoArray;
///then in the .m
-
(void) viewDidLoad { myPhotoArray =
[[NSMutableArray alloc]init];
}
//However Your getting images
-
(void) someOtherMethod {
UIImage
...
iphone从一个图片截取部分区域生成新的小图
UIImage *image = [[UIImage alloc] initWithData:data];//大图

CGRect imageRect = CGRectMake(0.0, 0.0, image.size.width, image.size.height);

CGSize itemSize = CGSizeMake(w,h);

UIGraphicsBeginImageContext(itemSize);

[image drawInRect:imageRect];
...
iphone显示本地的图片【代码】
- (void)viewDidLoad

{

NSString *homeDirectoryPath = NSHomeDirectory();

NSString *imagePath = [homeDirectoryPath stringByAppendingString:@"/graph.png"];

NSLog(@"Image: %@", imagePath);


if (![[NSFileManager
defaultManager] fileExistsAtPath:imagePath isDirectory:NULL])
...
在Xcode中安装部署及使用JSON.framework(附代码示例)
在Xcode中安装部署JSON
1.下载JSON_2.3.dmg到电脑,双击安装.下载地址:http://code.google.com/p/json-framework/downloads/list?can=1&;q=&colspec=Filename+Summary+Uploaded+ReleaseDate+Size+DownloadCount
如下图:


2.把上图中JSON目录拖拽到Xcode中classes目录,然后在自己的单元文件中就可以使用JSON了(例如:#import "JSON/JSON.h")。
...
objective-c对象retain和copy的区别
原来简单解释过属性定义(Property) ,并且提起了简单的retain,copy,assign的区别。那究竟是有什么区别呢?

assign就不用说了,因为基本上是为简单数据类型准备的,而不是NS对象们。

Retain vs. Copy!!

copy: 建立一个索引计数为1的对象,然后释放旧对象
retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1

那上面的是什么该死的意思呢?

Copy其实是建立了一个相同的对象,而retain不是:

比如一个NSString对象,地址为0×1111,内容为@”STR”
...
使用NSOperation+NSOperationQueue实现多任务网络连接
在网络应用程序中,经常需要多任务连接来提高程序的性能。比如多任务下载,多任务HTTP请求等,即线程控制模型中的工作群模型。使用 NSOperation 可以很容易实现这个功能。下面就以使用NSOperation处理并行的HTTP请求为例子,说明其用法。
首先准备一个 NSOperation 的子类,用于处理 HTTP 请求。

@interface RequestOperation : NSOperation {
NSURLRequest* _request;
NSMutableData* _data;
...
NSMutableURLRequest实现向web服务器POST JSON数据
======================================
objective-c代码:

======================================
NSLog(@"POST");


NSArray *arr = [[NSArray
alloc] initWithObjects:@"username",@"password",nil];


NSString *requestString = [NSString stringWithFormat:@"json=%@", [arr JSONRepresentation], nil];;
...
使用xib文件来快速创建自定义风格的table view[独家图文 ]
1。创建view-based工程图


2.用ib打开...controller.xib文件,拖入一个table view。



3。在classes目录下创建UITableView文件,取名为BagItemCell。


.h文件,.m文件不用改

#import

@interface BagItemCell : UITableViewCell {


IBOutlet
UILabel *lblName;

}

@property (nonatomic,retain) UILabel *lblName;
...
iPhone 异步加载图片[附代码]
AsyncImageView.h文件
@interface AsyncImageView : UIView {
NSURLConnection* connection;
NSMutableData* data;
}
@end

AsyncImageView.m文件
@implementation AsyncImageView

- (void)loadImageFromURL:(NSURL*)url {
if (connection!=nil) { [connection release; }
...
«5678910111213141516171819»

日历

<< 2014-10 >>

Sun

Mon

Tue

Wed

Thu

Fri

Sat

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

最近发表

Copyright 2011-2015 BuildApp.Net. All Rights Reserved.