
代码示例
coderKeNan
爱编程,爱运动,爱音乐,爱生活的一个IT男。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
实现图片抛物线的效果
实现图片抛物线的效果最近做项目,需要实现图片抛物线效果,研究了下,方法有二;方法一:-(void)isButtonClicked:(id)sender{ CGRect rect = [self.viewconvertRect:((UIButton *)sender).boundsfromView:sender]; UII原创 2012-08-29 11:14:42 · 2532 阅读 · 0 评论 -
将UIPickerView横放到UIActionSheet中
如何将UIPickerView调整大小后放入UIActionSheet中,我成功的实现了,现将代码贴出来。-(void)buttonClick:(id)sender{ UIActionSheet *actionSheet = [[UIActionSheetalloc] initWithTitle:@"请选择自动选取号码的个数:\n\n\n\n"转载 2012-10-11 22:14:27 · 1988 阅读 · 0 评论 -
导航条的颜色设置
一般以软件中会有导航条,系统会默认提供几种颜色,但仍然可以选择的比较少,可以通过自定义颜色来设置导航条的颜色,具体方法只要一句话就可以了:navigationController.navigationBar.tintColor = [UIColor colorWithRed:(21.0/255.0) green:(153.0 / 255.0) blue:(224.0 / 255.0) alph原创 2012-10-12 23:00:52 · 1802 阅读 · 0 评论 -
使用定制的NSDictionary的方法,对NSArray进行排序
NSArray中存放的是NSDictionary,可以使用策略的方法对NSDictionary进行定制,增加比较的方法。然后调用NSArray的sortUsingSelector方法对数组进行排序,这里使用NSDictionay中的时间对象的时间排序。具体操作如下:1.定制NSDictionaryXXX.h文件@interface NSMutableDictionary(myCompa转载 2012-10-12 23:09:21 · 837 阅读 · 0 评论 -
从图片中一点取色
最近看这个比较多人用到,以前有使用过,现在,粘过来给大伙看看.注意:UIImageView的大小只能跟图片一样大.要不然取色不对.- (UIColor *) getPixelColorAtLocation:(CGPoint)point { UIColor* color = nil; CGImageRef inImage = sel转载 2012-10-12 22:53:40 · 831 阅读 · 0 评论 -
[多媒体、图形、动画] 使用quartz2D绘制阴影的代码
void MyDrawWithShadows (CGContextRef myContext, // 1 float wd, float ht); { CGSize myShadowOffset = CGSizeMake (-15, 20);// 2 float myColor转载 2012-10-13 07:29:13 · 444 阅读 · 0 评论 -
UILocalNotification实现本地的闹钟提醒的方法
UILocalNotification *notification=[[UILocalNotification alloc] init]; if (notification!=nil) { NSDate *now=[NSDate new]; //notif原创 2012-10-12 22:58:11 · 771 阅读 · 0 评论 -
UIImageView实现图片幻灯片
NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"Image1.png"], [UIImage imageNamed:@"Image2.png"], [UIImage imageNamed:@"Image3.png"], [UIImage imageNamed:@"mag原创 2012-10-12 23:11:38 · 575 阅读 · 0 评论 -
短信,电话,邮件,提示框
+ (void)alert:(NSString *)msg{ UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:msg message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] autorelease];转载 2012-10-12 23:13:00 · 549 阅读 · 0 评论 -
UIWebView加载Loading...两种方法
UIWebView加载Loading...两种方法 第一种方法:使用UIView and UIActivityIndicatorView//创建UIWebViewWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, 400)];[WebView setUserInteractionE转载 2012-10-13 07:22:59 · 557 阅读 · 0 评论 -
通过代码添加联系人到通讯录的方法
-(IBAction)addToContact{ printf("--------addToContact----Execute!!!------\n"); ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate(); ABRecordRef newPerson =转载 2012-10-14 08:11:14 · 1551 阅读 · 0 评论 -
让模拟器也支持GPS定位(模拟实现)
iOS上的GPS定位一般需要真机才能看到效果,但在开发的过程中,一般都在模拟器上调试。那怎么办呢?我们可以使用Object-C的策略,给模拟器指定一个经纬度,这样,定位就可以在模拟器上实现了。RealTool为你实现一个简单的demo。// 模拟器 宏定义#ifdef TARGET_IPHONE_SIMULATOR @interface CLLocationManager (Sim转载 2012-10-14 08:24:08 · 4868 阅读 · 0 评论 -
分享别人的两种闹钟的实现方法
clock2是使用 UILocalNotification,详见http://www.devdiv.com/thread-69786-1-1.htmlmultitask_demo.zip是前两天看见http://www.devdiv.com/article-1675-1.html两种方法都可以实现,供大家学习。转载 2012-10-14 08:32:26 · 736 阅读 · 0 评论 -
iOS屏幕旋转
ios 屏幕旋转总结通过人为的办法改变view.transform的属性。具体办法: view.transform一般是View的旋转,拉伸移动等属性,类似view.layer.transform,区别在于 View.transform是二维的,也就是使用仿射的办法通常就是带有前缀CGAffineTransform的类(可以到API文档里面搜索这个前 缀的原创 2013-05-14 21:45:59 · 867 阅读 · 0 评论 -
打印出info.plist中所有keys,values的代码例子
NSBundle* mainBundle = [NSBundlemainBundle]; NSDictionary* infoDictionary = [mainBundle infoDictionary]; id key; NSArray* keys = [infoDictionary allKeys]; NSLog(@"Displ转载 2013-06-14 09:12:44 · 890 阅读 · 0 评论 -
判断手机,邮箱格式合法性
一、最简单的就是利用系统的NSPredicate//利用正则表达式验证- (BOOL)validateEmail:(NSString *)email { @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"翻译 2012-08-28 11:13:23 · 1459 阅读 · 0 评论 -
创建没有按钮的UIAlertView
alert = [[[UIAlertViewalloc]initWithTitle:@"\r\rConfiguring Preferences\rPlease Wait..." message:nildelegate:selfcancelButtonTitle:nilotherButton原创 2013-09-05 12:16:49 · 688 阅读 · 0 评论 -
IOS开发UI篇之──自定义加载等待框(MBProgressHUD)
这里介绍一下网友开源的MBProgressHUD类,实现等待框,一、网上下载 MBProgessHUD 类文件,直接导入到工程即可二、示例分析在我的工程中示例如下:1)在ShowImageViewController.h头文件代码如下:#import #import "MBProgressHUD.h"@interface ShowImageView转载 2012-10-11 21:39:10 · 757 阅读 · 0 评论 -
如何自定义UIActionSheet中的内容
UIActionSheet和UIAlertView因为UI有特殊的用途,所以本身并不允许你AddSubview之类的函数来自定义界面。解决的办法是继承它,实现一个自定义类,重载layoutSubviews函数。#import @interface UIImageActionSheet :UIActionSheet{ UIImage *titleI转载 2012-10-11 12:34:30 · 893 阅读 · 0 评论 -
UITextField抖动动画
最近做项目,需求中要求用户名或密码输错时,输入框要抖动(类似Mac登录密码错误的抖动效果)。现将代码分享出来:@interface UITextField (YHShakeUITextField)- (void) shake;@end#import "YH-TextField.h"#import @implementati原创 2012-09-04 17:19:19 · 2619 阅读 · 0 评论 -
用摄像头画面做 view 背景的代码例子
用摄像头画面做 view 背景的代码例子 本文转自 http://blog.youkuaiyun.com/favormm/archive/2011/06/28/6573336.aspx,用摄像头画面做 view 背景,非常酷。This action starts camera as a backgroud of the view:--(IBAction)btnStartCam转载 2012-08-28 10:15:14 · 574 阅读 · 0 评论 -
图片旋转
图片旋转if (image.size.width >= 470.0f) {UIView *rotatedViewBox = [[UIViewalloc]initWithFrame:CGRectMake(0,0,image.size.width, image.size.height)];CGAffineTransform t =CGAf翻译 2012-08-28 10:32:43 · 818 阅读 · 0 评论 -
UITextField里加label
UITextField里加图片,label UIImage *sinaImage =UIImageGetImageFromName(@"sina.png"); UIImageView *sinaImgv = [[UIImageViewalloc]initWithFrame:CGRectMake(5, -13, sinaImage.size.width,原创 2012-08-28 10:46:38 · 1548 阅读 · 0 评论 -
给UIImageView添加阴影和边框
给UIImageView添加阴影和边框UIImageView *_iconView = [[UIImageViewalloc]init];//添加边框 CALayer *layer = [_iconViewlayer]; layer.borderColor = [[UIColorwhiteColor]CGColor]; layer.b翻译 2012-08-28 11:00:15 · 2795 阅读 · 0 评论 -
保存图片到相册
保存图片到相册//接口中定义这个方法,然后在实现类中实现它-(void)imageSavedToPhotosAlbum:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo;//实现类中实现-(void)imageS转载 2012-08-28 11:06:56 · 899 阅读 · 0 评论 -
在ios中的Document中创建多级文件夹以及文件
在ios中的Document中创建多级文件夹以及文件-(NSString *)dataPath:(NSString *)file{ NSString *path = [[NSHomeDirectory()stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:转载 2012-08-28 11:10:20 · 1934 阅读 · 0 评论 -
让UILabel具有链接功能,点击后调用safari打开网址
让UILabel具有链接功能,点击后调用safari打开网址 UILabel *labelGovUrl = [[UILabelalloc]initWithFrame:CGRectMake(73.0,330.0,180.0,40.0)]; labelGovUrl.autoresizingMask = (UIViewAutoresizi翻译 2012-08-28 11:11:06 · 2932 阅读 · 0 评论 -
通过代码判断iphone4的Retina 屏幕分辨率
通过代码判断iphone4的Retina 屏幕分辨率#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,960), [[UIScreen mainScreen] currentMode].size)翻译 2012-08-28 11:12:18 · 16098 阅读 · 0 评论 -
自定义UINavigationItem.rightBarButtonItem
自定义UINavigationItem.rightBarButtonItem_segmentedControl = [[UISegmentedControlalloc]initWithItems:[NSArrayarrayWithObjects:@"免费",@"付费",nil]]; _segmentedControl.frame =CGRectMak原创 2012-08-28 10:56:39 · 1597 阅读 · 0 评论 -
日期格式化
日期格式化 NSDateFormatter *formatter = [[NSDateFormatteralloc]init]; [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"]; NSTimeZone *timeZone = [NSTimeZonetimeZoneWithName:@"Asia/S翻译 2012-08-28 11:02:15 · 520 阅读 · 0 评论 -
NSString 支持中文编码
NSString 支持中文编码NSString *nameString = [self.nameTextField.textstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];原创 2012-08-28 11:03:04 · 1119 阅读 · 0 评论 -
给UIImageView加手势
给UIImageView加手势UITapGestureRecognizer *tapgesture = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(click)]; [imageViewaddGestureRecognizer:tapgesture];翻译 2012-08-28 11:04:31 · 549 阅读 · 0 评论 -
Objective-C 的延迟执行某个函数
Objective-C 的延迟执行某个函数[selfperformSelector:@selector(doneLoadingTableViewData)withObject:nilafterDelay:0];翻译 2012-08-28 11:05:41 · 1445 阅读 · 0 评论 -
浏览Document文件夹下面的所有文件夹和文件列表
浏览Document文件夹下面的所有文件夹和文件列表NSFileManager *fileManager = [NSFileManagerdefaultManager]; //在这里获取应用程序Documents文件夹里的文件及文件夹列表 NSString *documentDir = [NSSearchPathForDirectories转载 2012-08-28 11:09:19 · 1117 阅读 · 0 评论 -
判断textField为空时让按钮不可用的代码
textField 为空时让按钮不可用,既防止误操作又显得应用很注重细节。- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {NSMutableString *newValue = [转载 2012-10-11 11:08:34 · 1669 阅读 · 0 评论 -
计算星期的代码
NSDateFormatter *inputFormatter = [[NSDateFormatteralloc]init]; [inputFormattersetDateFormat:@"yyyy-MM-dd 'at' HH:mm"]; NSDate *formatterDate = [inputFormatterdateFromString:@"2原创 2013-09-05 11:14:27 · 1235 阅读 · 0 评论