09 2011 档案
摘要:点引用是地道的Objective-C 2.0的风格。它被使用于简单的属性set、get操作,但对象的其它行为不应该使用它。Setters中对NSString进行copy永远不要仅仅retain一个字符串。这避免了调用者在你不知道的情况下对字符串作出了修改。不要作出那样的假设:你接受的对象是一个NSString对象而不是NSMutableString对象。- (void)setFoo:(NSString *)aFoo {[foo_ autorelease];foo_ = [aFoo copy];}总结:接受NSString作为参数的setter,应该copy它所接受的字符串。这从逻辑上遵守了NS
阅读全文
摘要:MBProgressHUD是替代UIProgressHUD的一个小工具,使用方法也非常简单下载地址是: http://github.com/matej/MBProgressHUD#import <UIKit/UIKit.h>#import "MBProgressHUD.h"@interface HudDemoViewController : UIViewController <MBProgressHUDDelegate> { MBProgressHUD *HUD;}- (IBAction) showWithLabel:(id)sender;- (vo
阅读全文
摘要:#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 (UITableView
阅读全文
摘要:自动补全 : esc查找项目文件:command+t查找文件内符号:shift+command+t跳到某行:command+l选择:shift+方向键向后缩进:option+tab向前缩进:shift+option+tabreformat 所选:option+command+[大写所选:control+u小写所选:control+shift+u查找:command+f查找下一个:command+gshow TODO list :control+shift+t计算数学公式:control+shift+c统计字数:control+shift+n注释与取消:command+/mate file 终端
阅读全文
摘要:UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];[self.view addGestureRecognizer:singleTap]; //这个可以加到任何控件上,比如你只想响应WebView,我正好填满整个屏幕singleTap.delegate = self;singleTap.cancelsTouchesInView = NO;[singleTap release];- (BOOL)gest
阅读全文
摘要:0CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文1 CGContextMoveToPoint 开始画线2 CGContextAddLineToPoint 画直线4 CGContextAddEllipseInRect 画一椭圆4 CGContextSetLineCap 设置线条终点形状4 CGContextSetLineDash 画虚线4 CGContextAddRect 画一方框4 CGContextStrokeRect 指定矩形4 CGContextStrokeRectWithWidth 指定矩形线宽度4 CGConte
阅读全文
摘要:-(void)viewDidLoad{array = [[NSMutableArray alloc] init];int i = 1;for(i;i<=30;i++){ [array addObject:[UIImageimageNamed:[NSString stringWithFormat:@"%d.jpg",i]]];}pictures.animationImages = array;pictures.animationDuration = 300;//时间间隔pictures.animationRepeatCount = 0;//循环播放[pictures s
阅读全文
摘要:CALayer的CATransition就可以. CATransition *animation = [CATransition animation]; [animation setDelegate:self]; // [animation setType:@"oglFlip"]; [animation setType:@"cube"]; //[animation setType:kCATransitionPush]; [animation setSubtype:direction]; [animation setDuration:1.0f]; [ani
阅读全文
摘要:const CGFloat kReflectPercent = -0.25f;const CGFloat kReflectOpacity = 0.3f;const CGFloat kReflectDistance = 10.0f;+ (void) addSimpleReflectionToView: (UIView *) theView{CALayer *reflectionLayer = [CALayer layer];reflectionLayer.contents = [theView layer].contents;reflectionLayer.opacity = kReflectO
阅读全文
摘要:把多张图片整合成连续动画,这恐怕是很多苹果开发者需要的功能。下面是单次播放和循环播放的代码:animationImageView.animationImages = imageFrames;// imageFrames 是一个图片数组 animationImageView是一个imageview[UIView setAnimationDelegate:self];animationImageView.animationDuration = 0.75f; animationImageView.animationRepeatCount = 3; [animationImageView startA
阅读全文
摘要:https://github.com/gabriel/gh-unit先记下来。
阅读全文
摘要:@interface Sample : NSObject { SEL action; id target; }@property SEL action;@property (assign) id target;-(void)addTarget:(id) t action:(SEL) s;-(void)sample_dosomthing;@end-----------------------------------#import "Sample.h"@implementation Sample@synthesize action;@synthesize target;-(vo
阅读全文
摘要:- (UIImage *)addImage:(UIImage *)image1 toImage:(UIImage *)image2 {UIGraphicsBeginImageContext(image1.size); // Draw image1[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)]; // Draw image2[image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)]; UIImage *
阅读全文
摘要:1.网上搜索字体文件(后缀名为.ttf,或.odf)2.把字体库导入到工程的resouce中3.在程序viewdidload中加载一下一段代码NSArray *familyNames = [UIFont familyNames];for( NSString *familyName in familyNames ){printf( "Family: %s \n", [familyName UTF8String] );NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];for( NSString *fo
阅读全文
摘要:UIImage *img = [[UIImage imageNamed:@"badge.png"]stretchableImageWithLeftCapWidth:16.0 topCapHeight:0.0];拉升图片视线
阅读全文
摘要:加载图片我一直在用[UIImage imageNamed:@"test.png"]; 使用也算正常,之后突然常常出现memory warnings问题,了解原理后发现application bundle的顶层文件夹寻找由供应的名字的图象 。 如果找到图片,装载到iPhone系统缓存图象。那意味图片是(理论上)放在内存里作为cache的。所以加载的图片太多就会这样, 改为 imageWithContentofFile 就解决了,在使用的时候可以灵活运用,各有长处。
阅读全文
摘要:我在现有的项目里面调用了MPMoviePlayerController 的 initWithContentURL方法,结果出现了EXC_BAD_ACCESS问题,纠结了两天了,今天终于被我找到原因了。发现线索:1、我先开弄了一个Demo来实现MPMoviePlayerController的正常使用,以确认MPMoviePlayerController的使用是正确的。2、我开始将MPMoviePlayerController的使用放到现有工程的入口出,以减少其它功能对此的影响。3、在不断的注释代码后终于发现在我最开始的时候调用了 NSNotificationCenter * nc = [NSNo
阅读全文
摘要:NSClassFromString是一个很有用的东西,尤其在进行iPhone toolchain的开发上。正常来说,id myObj = [[NSClassFromString(@"MySpecialClass") alloc] init];和id myObj = [[MySpecialClass alloc] init];是一样的。但是,如果你的程序中并不存在MySpecialClass这个类,下面的写法会出错,而上面的写法只是返回一个空对象而已。因此,在某些情况下,可以使用NSClassFromString来进行你不确定的类的初始化。比如在iPhone中,NSTask可
阅读全文
摘要:转:http://www.raywenderlich.com/2502/introduction-to-calayers-tutorialIf you’ve been programming for the iPhone, you’re probably really familiar with UIViews – buttons, text areas, sliders, web views, and more are all subclasses of UIView.But you might not know much about the technology that UIView i
阅读全文
浙公网安备 33010602011771号