您的位置:首页 > 其它

关于Iphone开发得一些案例及常用知识(转过来的参考用)

2012-02-22 22:07 453 查看
http://www.cnblogs.com/luyinghuai/archive/2011/08/29/2158328.html

bBar透明的效果

http://www.cocoachina.com/bbs/read.php?tid=17815

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];

--------------------------

设置Table Cell的背景图的公用类代码

http://www.cocoachina.com/downloads/video/2010/0521/1531.html

#import <Foundation/Foundation.h>

#import <UIKit/UIKit.h>

@interface UITableViewCell (UITableViewCellExt)

- (void)setBackgroundImage:(UIImage*)image;

- (void)setBackgroundImageByName:(NSString*)imageName;

@end

#import "UITableViewCellExt.h"

@implementation UITableViewCell (UITableViewCellExt)

- (void)setBackgroundImage:(UIImage*)image

{

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

imageView.contentMode = UIViewContentModeCenter;

self.backgroundView = imageView;

[imageView release];



}

- (void)setBackgroundImageByName:(NSString*)imageName

{

[self setBackgroundImage:[UIImage imageNamed:imageName]];

}

@end

调 用示例:

// Customize the appearance of table view cells.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {



static NSString *CellIdentifier = @"Cell";



UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]
autorelease];



cell.selectionStyle = UITableViewCellSelectionStyleNone;



[cell setBackgroundImageByName:@"text-background.png"];





}



return cell;

}

-------------------------------------

iPhone SDK
解析 xml的官方示例代码

http://www.cocoachina.com/downloads/video/2010/0520/1523.html

----------------------------------------------

把图片切成圆角代码

http://www.cocoachina.com/bbs/read.php?tid-1757.html

static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth,

float ovalHeight)

{

float fw, fh;

if (ovalWidth == 0 || ovalHeight == 0) {

CGContextAddRect(context, rect);

return;

}



CGContextSaveGState(context);

CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));

CGContextScaleCTM(context, ovalWidth, ovalHeight);

fw = CGRectGetWidth(rect) / ovalWidth;

fh = CGRectGetHeight(rect) / ovalHeight;



CGContextMoveToPoint(context, fw, fh/2); // Start at lower right corner

CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); // Top right corner

CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner

CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner

CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right



CGContextClosePath(context);

CGContextRestoreGState(context);

}

+ (id) createRoundedRectImage:(UIImage*)image size:(CGSize)size

{

// the size of CGContextRef

int w = size.width;

int h = size.height;



UIImage *img = image;

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);

CGRect rect = CGRectMake(0, 0, w, h);



CGContextBeginPath(context);

addRoundedRectToPath(context, rect, 10, 10);

CGContextClosePath(context);

CGContextClip(context);

CGContextDrawImage(context, CGRectMake(0, 0, w, h), img.CGImage);

CGImageRef imageMasked = CGBitmapContextCreateImage(context);

CGContextRelease(context);

CGColorSpaceRelease(colorSpace);

return [UIImage imageWithCGImage:imageMasked];

}

直接调用 createRoundedRectImage....

返回圆角图片

圆角大小自行修改 CGContextAddArcToPoint....

-------------------------------

检测iPhone/iPod Touch/iPad设备类型

http://www.cocoachina.com/bbs/read.php?tid-20994.html

-------------------------------------

iPhone上气泡式聊天的代码

http://www.cocoachina.com/downloads/video/2010/0510/1379.html

聊天程序--(UDP通信,bubble代码)

http://www.cocoachina.com/bbs/read.php?tid-24324-fpage-2.html

第一个iphone小程序(实现聊天功能)

http://www.cocoachina.com/bbs/read.php?tid-24956-fpage-2.html

----------------------------------------

ExpanderController可伸缩框架的代码

http://www.cocoachina.com/downloads/video/2010/0510/1368.html

-------------------------------------------

一段模拟水波纹的代码,希望对大家有用

http://www.cocoachina.com/downloads/video/2010/0506/1351.html

-------------------------------

根据经纬度计算两点之间距离的Obcective-C代码

http://www.cocoachina.com/downloads/video/2010/0506/1344.html

其中其中er 就是地球椭球半径,对于google map使用 6378137 就可以了。函数的调用非常简单,几乎使用任何平台:)

#define PI 3.1415926

double LantitudeLongitudeDist(double lon1,double lat1,

double lon2,double lat2)

{

double er = 6378137; // 6378700.0f;

//ave. radius = 6371.315 (someone said more accurate is 6366.707)

//equatorial radius = 6378.388

//nautical mile = 1.15078

double radlat1 = PI*lat1/180.0f;

double radlat2 = PI*lat2/180.0f;

//now long.

double radlong1 = PI*lon1/180.0f;

double radlong2 = PI*lon2/180.0f;

if( radlat1 < 0 ) radlat1 = PI/2 + fabs(radlat1);// south

if( radlat1 > 0 ) radlat1 = PI/2 - fabs(radlat1);// north

if( radlong1 < 0 ) radlong1 = PI*2 - fabs(radlong1);//west

if( radlat2 < 0 ) radlat2 = PI/2 + fabs(radlat2);// south

if( radlat2 > 0 ) radlat2 = PI/2 - fabs(radlat2);// north

if( radlong2 < 0 ) radlong2 = PI*2 - fabs(radlong2);// west

//spherical coordinates x=r*cos(ag)sin(at), y=r*sin(ag)*sin(at), z=r*cos(at)

//zero ag is up so reverse lat

double x1 = er * cos(radlong1) * sin(radlat1);

double y1 = er * sin(radlong1) * sin(radlat1);

double z1 = er * cos(radlat1);

double x2 = er * cos(radlong2) * sin(radlat2);

double y2 = er * sin(radlong2) * sin(radlat2);

double z2 = er * cos(radlat2);

double d = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));

//side, side, side, law of cosines and arccos

double theta = acos((er*er+er*er-d*d)/(2*er*er));

double dist = theta*er;

return dist;

}

----------------------------

巴黎自行车信息查询软件源码

http://www.cocoachina.com/downloads/video/2010/0429/1266.html

--------------------------------

*** iPhone DataGrid 数据列表组件,支持行列锁定

http://www.cocoachina.com/downloads/video/2010/0429/1267.html

--------------------------------

iPhone播放本地视频的代码

http://www.cocoachina.com/downloads/video/2010/0428/1260.html

----------------------------

UIWebView里面长按一个链接后自定义弹出菜单

http://www.cocoachina.com/iphonedev/sdk/2010/0716/1879.html

-------------------------------------------

iPhone上画面切换特效及代码

http://www.cocoachina.com/downloads/video/2010/0419/1123.html

-------------------------

永远的扫雷英雄(开源) 登场

http://www.cocoachina.com/bbs/read.php?tid-12818.html

--------------------------------

在iPhone中实现图片缩放

http://www.cocoachina.com/iphonedev/toolthain/2009/0611/198.html

-----------------

创建iPhone锁定划动条的方法

http://www.cocoachina.com/iphonedev/toolthain/2009/0611/224.html

-------------

UICoverFlowLayer例子:***iPhone的Cover Flow效果

http://www.cocoachina.com/iphonedev/toolthain/2009/0611/196.html

-----------------------------

如何在iPhone程序读取数据时显示进度窗

http://www.cocoachina.com/iphonedev/toolthain/2009/0611/173.html

-----------------

UITabBarController 保存调整后的more选项(增加所有TabBar之间切换).

http://www.cocoachina.com/bbs/read.php?tid-12424.html

--------------------------------------------

NSStirng、NSArray、以及枚举(Method小集合)

http://www.cocoachina.com/bbs/read.php?tid-7735.html

------------

UIview动画

http://www.cocoachina.com/bbs/read.php?tid-8035-keyword-demo.html

http://www.cocoachina.com/bbs/read.php?tid-11343.html

----------------

搜索功能

http://www.cocoachina.com/bbs/read.php?tid-5869.html

-------------

UILabel显示换行的方法

UILabel*label;

//设置换行

label.lineBreakMode = UILineBreakModeWordWrap;

label.numberOfLines = 0;

换行符还是\n

比如NSString * xstring=@"lineone\nlinetwo"

记得要把label的高度设置的足够显示多行内容。

------------------

手把手教你做iphone的soap应用(webservice)

http://www.cocoachina.com/bbs/read.php?tid-16561-fpage-2.html

---------------------------

点击Table一行弹出下拉一排按钮的TableViewCell类

http://www.cocoachina.com/bbs/read.php?tid-23065-fpage-2.html

http://www.cocoachina.com/bbs/read.php?tid=21494&page=1#131711

-----------------

一些iPhone开源项目代码

http://www.cocoachina.com/bbs/read.php?tid-4532-fpage-2.htm

----------------------

<iOS4>后台运行(Multitasking)以及本地通知(Local Notifications) 有图,有书,有代码,统一打包

http://www.cocoachina.com/bbs/read.php?tid-20423-fpage-2.html

-------------------

开源一个基于MultiTouch事件图片移动和缩放的demo

http://www.cocoachina.com/bbs/read.php?tid-25387-fpage-2.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: