iphone开发中一些常用的内容
来源:互联网 发布:暖气片造价知乎 编辑:程序博客网 时间:2024/05/19 05:34
UIEdgeInsets 设置包围tableView的坐标
- typedef struct UIEdgeInsets {
- CGFloat top, left, bottom, right; // specify amount to inset (positive) for each of the edges. values can be negative to 'outset'
- } UIEdgeInsets;
里面分别是上,左,下,右的包围长度,往下拖动时,如果top 》 0, 就会显示出来,如果小于0就会隐藏。
计算字符串的显示长度
- CGSize detailSize = [@"你的字符串" sizeWithFont:[UIFont systemFontOfSize:15]
- constrainedToSize:CGSizeMake(200, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap];
navigationbar的back键触发其他事件
- UIButton *back =[[UIButton alloc] initWithFrame:CGRectMake(200, 25, 63, 30)];
- [back addTarget:self act
- ion:@selector(reloadRowData:) forControlEvents:UIControlEventTouchUpInside];
- [back setImage:[UIImage imageNamed:@"返回按钮.png"] forState:UIControlStateNormal];
- UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:back];
- self.navigationItem.leftBarButtonItem = loginButtonItem
- [back release];
- [backButtonItem release];
防止屏幕暗掉锁屏
- [[UIApplication sharedApplication] setIdleTimerDisabled:YES];
显示网络活动状态指示符
这是在iPhone左上部的状态栏显示的转动的图标指示有背景发生网络的活动。
- UIApplication* app = [UIApplication sharedApplication];
- app.networkActivityIndicatorVisible = YES;
获取UUID
- [[UIDevice currentDevice] uniqueIdentifier]
- UIDevice *myDevice = [UIDevice currentDevice];
- NSString *deviceID = [myDevice uniqueIdentifier];
截取屏幕图片
- UIGraphicsBeginImageContext(CGSizeMake(200,400)); //创建一个基于位图的图形上下文并指定大小为CGSizeMake(200,400)
- [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; //renderInContext 呈现接受者及其子范围到指定的上下文
- UIImage *aImage = UIGraphicsGetImageFromCurrentImageContext(); //返回一个基于当前图形上下文的图片
- UIGraphicsEndImageContext(); //移除栈顶的基于当前位图的图形上下文
- imageData = UIImagePNGRepresentation(aImage); //以png格式返回指定图片的数据
应用程序边框大小
我们应该使用"bounds"来获得应用程序边框。不是用"applicationFrame"。"applicationFrame"还包含了一个20像素的status bar。除非我们需要那额外的20像素的status bar。
震动和声音播放
- Sound will work in the Simulator, however some sound (such as looped) has been
- reported as not working in Simulator or even altogether depending on the audio format.
- Note there are specific filetypes that must be used (.wav in this example).
- AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
- SystemSoundID pmph;
- id sndpath = [NSBundle mainBundle] pathForResource:@"mySound" ofType:@"wav" inDirectory:@"/"];
- CFURLRef baseURL = (CFURLRef) [NSURL alloc] initFileURLWithPath:sndpath];
- AudioServicesCreateSystemSoundID (baseURL, &pmph);
- AudioServicesPlaySystemSound(pmph);
- [baseURL release];
Iphone获取本机IP
- -(NSString *)getAddress {
- char iphone_ip[255];
- strcpy(iphone_ip,"127.0.0.1"); // if everything fails
- NSHost* myhost =[NSHost currentHost];
- if (myhost)
- {
- NSString *ad = [myhost address];
- if (ad)
- strcpy(iphone_ip,[ad cStringUsingEncoding:NSASCIIStringEncoding]);
- }
- return [NSString stringWithFormat:@"%s",iphone_ip];
- }
NSString转化为UNICODE String:
(NSString*)fname = @“Test”;char fnameStr[10];memcpy(fnameStr, [fname cStringUsingEncoding:NSUnicodeStringEncoding], 2*([fname length]));
NSString转化为char
(NSString*)fname = @“Test”;char fnameStr[10];fnameStr =[fname UTF8String];
char -> NSData:
char * postData = "TEST"; NSData *data = [NSData dataWithBytes:postData length:strlen(postData)]; 转换为NSString: - (id)initWithUTF8String:(const char *)bytes 然后用NSString的 - (NSData *)dataUsingEncoding:(NSStringEncoding)encodingNSData ->char
NSData returnData; char* bu=[returnData bytes];NSData->NSString
NSString* aStr; aStr = [NSString alloc] initWithData:aData encoding:NSASCIIStringEncoding];NSString->NSData
NSData* aData; aData = [aStr dataUsingEncoding: NSASCIIStringEncoding];
- iphone开发中一些常用的内容
- iphone开发 常用的一些
- 收集的开发中常用内容总结
- iphone 开发过程中一些问题的解决方法(MPMoviePlayController)
- iphone 开发过程中一些问题的解决方法(NSDate)
- iPhone开发中混用objc,c,c++的一些问题
- 记录一些mac和iPhone开发的东西,都是info.plist的内容
- 一些iphone开发的资料
- 一些iphone开发的资料
- iPhone开发的一些资源
- iPhone开发的一些资源
- 开发中常用的一些工具
- Android 开发中一些常用的代码
- ios开发中常用的一些软件
- iOS 开发中常用的一些宏
- Windows开发中一些常用的辅助工具
- 开发中常用的一些命令
- 开发中常用的一些命令
- axis设置SoapHeader
- sqlserver大数据归档
- Tomcat 6中配置SSL双向认证
- ECLIPSE快捷键
- c/c++/MFC 调用 js 函数代码
- iphone开发中一些常用的内容
- 除了Java之外你需要知道的事情1 ——通过equals方法讲讲离散数学
- JS刷新iframe和打印页面的iframe内容
- linux SSH双向配置
- ipad/iphone内存管理三之NoAutorelease和Autorelease详细解说
- 加密解密url QueryString 发生 Invalid length for a Base-64 char array异常解决方法
- 这样去写你的 HTML.
- 如何在一台机器同时启动两个TOMCAT
- JDK Logging深入分析