随笔分类 -  ios小技巧

iOS应用检查更新的最优方法
摘要:虽然App Store能够提醒用户软件更新,但很多用户不会主动去更新一大堆的软件(我机器上待更新的软件在100个左右)。如果在软件开启时提醒用户更新 或者 更多中设置“检查更新”项,效果会好很多。 通常的做法是在自己的服务器上记录最新版本号,从iOS客户端请求,与本地版本号比较,不同则提示更新。这种做法简单,缺点是需要单独的服务器支持。 通过查阅相关文章,找到了如下方法,与上述方法类似,不过不需要另外的服务器支持。此为检查更新的最优方法。[html] view plaincopyNSString*version=@"";NSURL*url=[NSURLURLWithStri 阅读全文

posted @ 2012-11-21 17:49 无量少年 阅读(617) 评论(0) 推荐(0)

UIWebView的点击事件
摘要:UIWebView的点击事件原来我自定义过UITextView,然后将捕获 touchesBegan,touchesMoved和touchesEnded的事件后交给父层去处理,这样就可以UITextView上进行手势翻页 等处理,今天想要故伎重演在UIWebView上,结果失败了。后来用了一种最最简单的办法实现了。你猜对了,是UITapGestureRecognizer,贴上代码。在UIViewController中,加入协议UIGestureRecognizerDelegate,然后.m文件里加入以下代码:UITapGestureRecognizer* singleTap = [[UITap 阅读全文

posted @ 2012-11-16 17:45 无量少年 阅读(264) 评论(0) 推荐(0)

圆角图片怎么画?
摘要: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));C 阅读全文

posted @ 2012-11-16 17:44 无量少年 阅读(340) 评论(0) 推荐(0)

iOS保存图片信息到相册
摘要:http://www.cnblogs.com/astin/archive/2012/08/02/2619569.html 阅读全文

posted @ 2012-11-16 17:34 无量少年 阅读(679) 评论(0) 推荐(0)

编程实现iPhone 启动项(转载)
摘要:如果想让程序自动启动,则需要使用4个方法,一个用来获取启动项的列表,一个用于向里面增加启动项,一个用来从里面移除一个启动项,还有一个用来将里面的启动项解析为URL.下面的方法用于获取启动项列表:================== LSSharedFileListCreate( CFAllocatorRef inAllocator, CFStringRef inListType, CFTypeRef listO... 阅读全文

posted @ 2012-11-15 18:13 无量少年 阅读(420) 评论(0) 推荐(0)

iPhone tableview分批显示数据
摘要:iPhone屏幕尺寸是有限的,如果需要显示的数据很多,可以先数据放到 一个table中,先显示10条,table底部有一察看更多选项,点击察 看更多查看解析的剩余数据。基本上就是数据源里先只放10条, 点击最后一个cell时, 添加更多的数据到数据源中. 比如:数据源是个array:NSMutableArray *items;ViewController的这个方法返回数据条数: +1是为了显示"加载更多"的那个cell- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSIntege 阅读全文

posted @ 2012-11-15 18:12 无量少年 阅读(384) 评论(0) 推荐(0)

Sqlite中文排序
摘要:原文:http://fei263.blog.163.com/blog/static/92793724201091211039242/Sqlite 是一个用C语言实现的小型SQL数据库引擎。它体积小巧但功能强大,对硬件资源要求很低而且性能表现卓越,非常适合于嵌入式应用环境。 最近发现sqlite并不支持中文(拼音/笔画)排序,而这个功能又是我们必需的,所以花了些时间去研究。我对Sqlite的了解只能算是业余级,在研究 的过程或许走了些弯路,或许已经有现存的算法可利用,不管怎么样,在研究过程中还是有不少收获,写出来和大家探讨一下。 我们知道,计算机中的每一个字符都有一个内码。在默认情况下,计算机排 阅读全文

posted @ 2012-11-15 18:11 无量少年 阅读(871) 评论(0) 推荐(0)

[iPhone类代码] 简单的多线程调用
摘要:在主线程里加入一个loading画面……2 {3 [window addSubview:view_loading];4 [NSThread detachNewThreadSelector:@selector(init_backup:) toTarget:self withObject:nil];5 }可以通过performSelectorOhMainThread更新UI元素,比如设置进度条等等。最后消除loading画面,载入主View。7 - (void)init_backup:(id)sender8 {9 NSAutoreleasePool *pool = [[NSAutoreleaseP 阅读全文

posted @ 2012-11-15 18:10 无量少年 阅读(151) 评论(0) 推荐(0)

生成随机guid串的代码
摘要:NSString * result; CFUUIDRef uuid; CFStringRef uuidStr; uuid = CFUUIDCreate(NULL); assert(uuid != NULL); uuidStr = CFUUIDCreateString(NULL, uuid); assert(uuidStr != NULL); result = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSStringstringWithFormat:@"%@-%@", prefix, uuidStr]]. 阅读全文

posted @ 2012-11-15 18:10 无量少年 阅读(249) 评论(0) 推荐(0)

NSTableView 文字过长的处理代码
摘要:如果在 NSTableView 里需要显示的文字太多,就需要只显示首尾,中间用 …… 代替。代码如下NSString *setByTrcanateWithAttributeForWidth(NSString *s,NSDictionary *attr,float wid,NSLineBreakMode truncateMode){NSSize textSize = [s sizeWithAttributes:attr];if(textSize.width <= wid){return s;}NSMutableString *currString = [NSMutableString st 阅读全文

posted @ 2012-11-15 18:08 无量少年 阅读(203) 评论(0) 推荐(0)

NSDateFormatter setDateFormat 自定義日期/時間格式
摘要: 阅读全文

posted @ 2012-11-15 18:07 无量少年 阅读(177) 评论(0) 推荐(0)

取得当前VIew或者UIImage某个点的RGB信息
摘要:(UIColor*) getPixelColorAtLocation:(CGPoint)point { UIColor* color = nil; CGImageRef inImage = self.image.CGImage; // Create off screen bitmap context to draw the image into. Format ARGB is 4 bytes for each pixel: Alpa, Red, Green, Blue CGContextRef cgctx = [self createARGBBitmapContextFromImage:inI 阅读全文

posted @ 2012-11-15 18:06 无量少年 阅读(306) 评论(0) 推荐(0)

消息通知方式设置旋转view
摘要:看到这篇不错, 直接转载过来了, 没什么可解释的,一看就明白 :)出处: http://www.marsiphone.cn/tag/uidevice/整个程序需要支持横竖屏切换得时候,会比较简单,在每个ViewController 的- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation方法中,return YES; 就好。可如果只是要某个VC( = View Controller)支持横竖屏切换呢?单独在那个view controller中像上面那样做是没有效果的。 阅读全文

posted @ 2012-11-15 18:06 无量少年 阅读(173) 评论(0) 推荐(0)

如何实现pushViewController:animated:的不同页面转换特效
摘要:1. 首先要明确的是,不使用pushViewController的默认动画,所以在调用这个函数时,要将animated设置为NO.2. 使用普通的来CATransition实现转换效果,代码如下:显示代码打印01CATransition *animation = [CATransition animation];0203[animation setDuration:0.3];0405[animation setType: kCATransitionMoveIn];0607[animation setSubtype: kCATransitionFromTop];0809[animation se 阅读全文

posted @ 2012-11-15 18:04 无量少年 阅读(463) 评论(0) 推荐(0)

如何移动组件的位置,例如如何将UIAlertView显示在屏幕上部
摘要:苹果自带的警告框非常好用,但是它总是显示在屏幕中间,我们如何将它的位置移动呢?从Iphone SDK3开始我们可以使用CGAffineTransformTranslateview plaincopy to clipboardprint?UIAlertView*alert=[[UIAlertViewalloc]initWithTitle:@"Alert"message:@"Alert"delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil];alert.transform=CG 阅读全文

posted @ 2012-11-15 18:03 无量少年 阅读(213) 评论(0) 推荐(0)

图片缩放代码
摘要://// TouchMoveScaleView.h// TouchMoveScaleDemo//// Created by jimney on 07/05/10.// Copyright 2010 OpenSource. All rights reserved.//Welcome to my HomePage In CocoaChina:http://www.cocoachina.com/bbs/u.php?action=topic#import <UIKit/UIKit.h>#import <QuartzCore/QuartzCore.h>/**类说明*此类主要实现在 阅读全文

posted @ 2012-11-15 18:01 无量少年 阅读(633) 评论(0) 推荐(0)

iphone开发中的一些小技
摘要:在iPhone开发过程中,一些小技巧对开发工作有很大的帮助作用,所以以下内容收集了一些开发过程中的小技巧。1、如果在程序中想对某张图片进行处理的话(得到某张图片的一部分)可一用以下代码: UIImage *image = [UIImage imageNamed :filename];CGImageRef imageRef = image.CGImage ;CGRect rect = CGRectMake (origin.x , origin.y ,size.width , size.height );CGImageRef imageRefRect = CGImageCreateWithImag 阅读全文

posted @ 2012-11-15 17:59 无量少年 阅读(192) 评论(0) 推荐(0)

把UIView覆盖到状态栏上的方法
摘要:http://blog.csdn.net/xianghuibeijing/article/details/6363925最近iPhone上的一个新闻阅读软件Reeder更新了, 非常好用, 稳定,而且速度飞快.这个软件征服我这个吹毛求疵的人的一个地方, 其实在于一个小细节, 有了这个细节, 我觉得, 这软件值了!这个细节就是系统状态栏图标, 从来没有一个程序在状态栏上做文章, Reeder 做到了, 新闻的刷新, 图片加载, 在系统状态栏上显示, 显得非常的苹果味道, 如图:当然, 本文是讨论技术, 不是软件评测.国外好多论坛上在问这个问题,但答案都是需要PrivateAPI之类的,无法上St 阅读全文

posted @ 2012-11-15 17:56 无量少年 阅读(398) 评论(0) 推荐(0)

修改UIAlertView背景
摘要:UIGraphicsBeginImageContext(theSize);[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];theImage = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();theAlert.layer.contents = (id)[theImage CGImage]; UIImageView * image = [theAlert valueForKey:@"_backgrou 阅读全文

posted @ 2012-11-15 17:55 无量少年 阅读(145) 评论(0) 推荐(0)

Iphone获取本机IP
摘要:-(NSString*)getAddress{ chariphone_ip[255]; strcpy(iphone_ip,"127.0.0.1");//ifeverythingfails NSHost*myhost=[NSHostcurrentHost]; if(myhost) { NSString*ad=[myhostaddress]; if(ad) strcpy(iphone_ip,[adcStringUsingEncoding:NSASCIIStringEncoding]); } return[NSStringstringWithFormat:@"%s&qu 阅读全文

posted @ 2012-11-15 17:53 无量少年 阅读(275) 评论(0) 推荐(0)

导航

点击右上角即可分享
微信分享提示