`
- 浏览:
719811 次
- 性别:
- 来自:
大连
-
一些代码片段
1. 16进制颜色值的转换
#define
UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue &
0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00)
>> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
2.md5
+ (NSString*)md5:(NSString*)str
{
constchar*cStr = [str UTF8String];
unsignedcharresult[16];
CC_MD5(cStr, strlen(cStr), result);
return[NSStringstringWithFormat:@"XXXXXXXXXXXXXXXX",
result[0], result[1], result[2], result[3],
result[4], result[5], result[6], result[7],
result[8], result[9], result[10], result[11],
result[12], result[13], result[14], result[15]
];
}
3.调用
//1、调用 自带mail
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"mailto://admin@hzlzh.com"]];
//2、调用 电话phone
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"tel://8008808888"]];
//3、调用 SMS
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"sms://800888"]];
//4、调用自带 浏览器 safari
[[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"http://www.hzlzh.com"]];
//调用phone可以传递号码,调用SMS 只能设定号码,不能初始化SMS内容。
4.计算2个经纬度之间距离
+(double)distanceBetweenOrderBy:(double)lat1:(double)lat2:(double)lng1:(double)lng2{
CLLocation* curLocation = [[CLLocationalloc]initWithLatitude:lat1longitude:lng1];
CLLocation* otherLocation = [[CLLocationalloc]initWithLatitude:lat2longitude:lng2];
doubledistance = [curLocation distanceFromLocation:otherLocation];
returndistance;
}
5.输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
text.clearButtonMode=UITextFieldViewModeAlways;
6.iOS本地推送
第一步:创建本地推送
// 创建一个本地推送
UILocalNotification*notification = [[[UILocalNotificationalloc]init]autorelease];
//设置10秒之后
NSDate*pushDate = [NSDatedateWithTimeIntervalSinceNow:10];
if(notification != nil) {
// 设置推送时间
notification.fireDate= pushDate;
// 设置时区
notification.timeZone= [NSTimeZonedefaultTimeZone];
// 设置重复间隔
notification.repeatInterval= kCFCalendarUnitDay;
// 推送声音
notification.soundName= UILocalNotificationDefaultSoundName;
// 推送内容
notification.alertBody= @"推送内容";
//显示在icon上的红色圈中的数子
notification.applicationIconBadgeNumber= 1;
//设置userinfo 方便在之后需要撤销的时候使用
NSDictionary*info = [NSDictionarydictionaryWithObject:@"name"forKey:@"key"];
notification.userInfo= info;
//添加推送到UIApplication
UIApplication*app = [UIApplicationsharedApplication];
[appscheduleLocalNotification:notification];
}
第二步:接收本地推送
- (void)application:(UIApplication*)application didReceiveLocalNotification:(UILocalNotification*)notification{
UIAlertView*alert = [[UIAlertViewalloc]initWithTitle:@"iWeibo"message:notification.alertBodydelegate:nilcancelButtonTitle:@"确定"otherButtonTitles:nil];
[alertshow];
// 图标上的数字减1
application.applicationIconBadgeNumber-= 1;
}
第三步:解除本地推送
// 获得 UIApplication
UIApplication*app = [UIApplicationsharedApplication];
//获取本地推送数组
NSArray*localArray = [app scheduledLocalNotifications];
//声明本地通知对象
UILocalNotification*localNotification;
if(localArray) {
for(UILocalNotification*noti inlocalArray) {
NSDictionary*dict = noti.userInfo;
if(dict) {
NSString*inKey = [dict objectForKey:@"key"];
if([inKey isEqualToString:@"对应的key值"]) {
if(localNotification){
[localNotificationrelease];
localNotification = nil;
}
localNotification = [noti retain];
break;
}
}
}
//判断是否找到已经存在的相同key的推送
if(!localNotification) {
//不存在初始化
localNotification = [[UILocalNotificationalloc]init];
}
if(localNotification) {
//不推送 取消推送
[appcancelLocalNotification:localNotification];
[localNotificationrelease];
return;
}
}
7.点击链接直接跳转到 App Store 指定应用下载页面
//跳转到应用页面
NSString*str = [NSStringstringWithFormat:@"http://itunes.apple.com/us/app/id%d",appid];
[[UIApplicationsharedApplication]openURL:[NSURLurlWithString:str]];
//跳转到评价页面
NSString*str = [NSStringstringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id;=%d",
appid ];
[[UIApplicationsharedApplication]openURL:[NSURLurlWithString:str]];
8.父级view 不响应touch事件 子view相应事件
-(id)hitTest:(CGPoint)pointwithEvent:(UIEvent*)event {
idhitView = [superhitTest:pointwithEvent:event];
if(hitView == self)returnnil;
elsereturn hitView;
}
9.给视图加上倒影效果
constCGFloat kReflectPercent = -0.25f;
constCGFloat kReflectOpacity = 0.3f;
constCGFloat kReflectDistance = 10.0f;
+ (void)addSimpleReflectionToView: (UIView*) theView
{
CALayer*reflectionLayer = [CALayerlayer];
reflectionLayer.contents= [theView layer].contents;
reflectionLayer.opacity= kReflectOpacity;
reflectionLayer.frame= CGRectMake(0.0f,0.0f,
theView.frame.size.width,
theView.frame.size.height* kReflectPercent);
CATransform3Dstransform = CATransform3DMakeScale(1.0f, -1.0f,1.0f);
CATransform3Dtransform = CATransform3DTranslate(stransform,0.0f,
-(kReflectDistance + theView.frame.size.height),0.0f);
reflectionLayer.transform= transform;
reflectionLayer.sublayerTransform= reflectionLayer.transform;
[[theViewlayer]addSublayer:reflectionLayer];
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
1.播放gif图片 2.读取网络图⽚ 3。多线程
Electric Hands 软件 iOS 代码片段 作者: Grzegorz Adam Hankiewicz < > 内容 编写多个应用程序时,不可避免地会重复代码段。 虽然通用库很好,但总会有一些代码片段在成熟的库中没有位置,最终会被复制和粘贴...
腾讯 QMUI Team 常用的 Xcode Code Snippets 代码片段,加速开发效率!.zip,用于Xcode使用的iOS通用代码片段,其中也包含若干专用于QMUI iOS框架的代码片段。
qmui-ios-codesnippets是一个QMUI团队日常工作中整理出来的Xcode的iOS通用代码片段集,其中也包含多个专用于iOS的QMUI框架的代码片段。 整理这个代码片段集的初衷有以下几点: 我们发现由于Xcode本身的功能不足,...
Snippetty是一款优秀的代码片段实时演示工具,可以让您轻松编辑代码,让您在最喜爱的Markdown编辑器中编写脚本。还可以帮你加载文件并实时进行代码演示。 应用介绍 Snippetty可以毫不费力的现场代码演示,每次都...
不错的资源,由于Demo过大不符合要求,所以只传片段代码
代码片段库Xcode中代码片段,已文件加载的形式展示,也就是说,代码片段是一个文件本库结构如下,只需将CB_Code_Snippets_library目录下的所有文件拷贝至Xcode代码片段文件夹中即可该代码片段库,对常用的代码片段进行了...
ios-watchkit-snippets ##Description 使用 WatchKit 制作 Apple Watch 应用程序的代码片段。 此 repo 中的每个文件夹代表一个不同的项目,如下所述。 ##语言迅捷###项目:HelloWatch 一个简单的“Hello World”...
块是一个独立的代码片段,始终存在于另一个编程结构的范围内,如在一个方法的主体。块可以捕获块外变量的值,但外部对于块内发生的事情一无所知。详细介绍 github.com/pro648/tips/wiki/Block的用法 在块内不能直接...
iOS 陀螺仪开发 及原理 源代码的说明、文档及片段
检测指定路径文件大小,最近做清除缓存的功能,要先显示占用多少内存,然后再清除,这个方法可以算出所占内存的多少,是代码片段,分享
该源码是和git仓库无缝同步代码片段,源码ACCodeSnippetRepositoryPlugin,ACCodeSnippetRepository可帮你和git仓库无缝同步代码片段,并且同步结果是易读的文本。
cos片段COS官方文档的代码片段快速导航语言代码示例安卓iOS(ObjC)iOS(快速)JavaJava脚本走PythonPHPNode.js小程序网络
代码片段: function setClosed() { li.each(function (index) { $(this).css('top', index * 4).css('width', width - index * 0.5 '%').css('margin-left', index * 0.25 '%'); }); li.addClass('closed...
StyleShare 中的 ReactorKit 代码片段 StyleShare中有用的ReactorKit代码片段的集合 安装 在安装之前退出Xcode并在终端中运行以下脚本: git clone https://github.com/StyleShare/ReactorKitCodeSnippets mkdir -p...
开源构建脚本和重要的代码片段 一些重要的构建脚本,用于在具有 arm64 支持的 iOS 平台中构建开源 C 库。 LIBIDN 构建脚本 原始构建脚本是在 xmppframework 项目中找到的,后来我修改了脚本以使用 iOS7 SDK 和 arm...
该应用程序目前仍处于开发阶段,我提供了自己对项目的贡献的代码片段,但这些代码片段并未构成整个代码库。 使用的技术: React本机 React本机NPM库 Redux 节点JS 表示 护照 PostgreSQL RESTful API 视频演练 ...
iOS8采样器 iOS 8新功能的代码示例。如何建造基本建立,但是请注意以下几点:供应配置文件尝试使用HealthKit或HomeKit示例时,必须使用启用了HealthKit或HomeKit的配置文件。内容音效使用AVAudioEngine的音频失真和...
一个小的iOS代码片段,用于创建动态链接的UIAlerts。 用法示例: fileprivate lazy var firstAction: ChainedAlertTree = { let cancelAction = ChainedAlertAction ( title : " Cancel " , style : . cancel , ...
它包含第 3 章中的所有代码片段。 下载或克隆此文件,并随时将这些片段应用到您自己的项目中。 ##第4章 本章是示例I18nExerciser项目的开始,练习具有国际化和本地化意识的 Objective-C 代码。 该项目使用每个...