好程序员ios开发小知识点(二)_程序员知识点
好程序员ios开发小知识点(二)由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“程序员知识点”。
、程序启动画面大小
iOS设备现在有三种不同的分辨率:iPhone 320x480、iPhone 4 640x960、iPad 768x1024。以前程序的启动画面(图片)只要准备一个 Default.png 就可以了,但是现在变得复杂多了。下面就是 CocoaChina 会员做得总结
如果一个程序,既支持iPhone又支持iPad,那么它需要包含下面几个图片: Default-Portrait.png iPad专用竖向启动画面 768x1024或者768x1004 Default-Landscape.png iPad专用横向启动画面 1024x768或者1024x748 Default-PortraitUpsideDown.png iPad专用竖向启动画面(Home按钮在屏幕上面),可省略 768x1024或者768x1004 Default-LandscapeLeft.png iPad专用横向启动画面,可省略 1024x768或者1024x748 Default-LandscapeRight.png iPad专用横向启动画面,可省略 1024x768或者1024x748 Default.png iPhone默认启动图片,如果没有提供上面几个iPad专用启动图片,则在iPad上运行时也使用Default.png(不推荐)320x480或者320x460 Default@2x.png iPhone4启动图片640x960或者640x920 为了在iPad上使用上述的启动画面,你还需要在info.plist中加入key: UISupportedInterfaceOrientations。同时,加入值UIInterfaceOrientationPortrait, UIInterfacOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight17、ASIHTTPRequest实现断点下载
-(IBAction)URLFetchWithProgre:(id)sender { [startButton setTitle:@“Stop” forState:UIControlStateNormal];[startButton addTarget:self action:@selector(stopURLFetchWithProgre:)forControlEvents:UIControlEventTouchUpInside];NSString*tempFile = [[[[NSBundle mainBundle] bundlePath]stringByDeletingLastPathComponent]stringByAppendingPathComponent:@“MemexTrails_1.0b1.zip.download”];if([[NSFileManager defaultManager] fileExistsAtPath:tempFile]){ [[NSFileManager defaultManager] removeItemAtPath:tempFile error:nil];} [self resumeURLFetchWithProgre:self];}(IBAction)resumeURLFetchWithProgre:(id)sender { [resumeButton setEnabled:NO];[startButton setTitle:@“Start” forState:UIControlStateNormal];[startButton addTarget:self action:@selector(stopURLFetchWithProgre:)forControlEvents:UIControlEventTouchUpInside];[networkQueue cancelAllOperations];[networkQueue setShowAccurateProgre:YES];[networkQueue setDownloadProgreDelegate:progreIndicator];[networkQueue setDelegate:self];[networkQueue setRequestDidFinishSelector:@selector(URLFetchWithProgreComplete:)];ASIHTTPRequest*request=[[[ASIHTTPRequest alloc] initWithURL:[NSURLURLWithString:@“http://9991.net/blog/mp3/2.mp3”]] autorelease];[request setDownloadDestinationPath:[[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@“MemexTrails_1.0b1.mp3”]];[request setTemporaryFileDownloadPath:[[[[NSBundle mainBundle] bundlePath]stringByDeletingLastPathComponent]stringByAppendingPathComponent:@“MemexTrails_1.0b1.zip.down”]];[request setAllowResumeForFileDownloads:YES];[networkQueue addOperation:request];
}(IBAction)throttleBandwidth:(id)sender { if([(UIButton *)sender state] ==YES){ [ASIHTTPRequest setMaxBandwidthPerSecond:ASIWWANBandwidthThrottleAmount];} else { [ASIHTTPRequest setMaxBandwidthPerSecond:];} }
18、Safari 启动本地app
在plist文件中加入URL types 结构如下图,在Safari中地址栏输入 设置的字符串,比如设置的是
QQ,地址栏输入 QQ:// 就可以起点本地应用。
19、拖到视频进度与滑动手势冲突解决办法
#pragma mark10.1.x system */ } else if(floor(NSAppKitVersionNumber)
} else { /* 10.6 or later system */ } 跟以上一样在 NSObjCRuntime.h中用定义了NSFoundationVersionNumber全局常量 小结:详解IOS SDK兼容性引导的内容介绍玩玩了,希望通过本文的学习能对你有所帮助!原文地址:http://blog.csdn.net/diyagoanyhacker/article/details/667334426、NSDate 与 NSString 转换
1、将字符串 “Fri Nov 11 09:06:27 +0800 2011” 转换成Date: NSDateFormatter *format = [[NSDateFormatter alloc] init];NSLocale *enLocale = [[NSLocale alloc] initWithLocaleIdentifier:@“en-US”];[format setLocale:enLocale];[enLocale release];[format setDateFormat:@“EEE MMM dd HH:mm: ZZZ yyyy”];NSDate *dateTime = [format dateFromString:meage];
将Date转换成字符串: NSDate *date = [NSDate date];NSString * dateString = [format stringFromDate:date];//字符串转换成NSDate 需要设置NSLocale 否则真机上会失败。
2、获取当前时间,转化成字符串
NSDateFormatter * formatter = [[NSDateFormatteralloc]init];formatter.dateStyle = NSDateFormatterMediumStyle;formatter.timeStyle = NSDateFormatterMediumStyle;formatter.locale = [NSLocalecurrentLocale];self.timeLabel.text = [formatterstringFromDate:[NSDatedate]];
3、获取月、日、年、时、分、秒
NSDateFormatter *formatter =[[[NSDateFormatteralloc] init] autorelease];formatter.dateStyle = NSDateFormatterMediumStyle;formatter.timeStyle = NSDateFormatterMediumStyle;formatter.locale = [NSLocalecurrentLocale];
NSDate *date = [NSDatedate];
[formatter setTimeStyle:NSDateFormatterMediumStyle];NSCalendar *calendar = [[[NSCalendaralloc] initWithCalendarIdentifier:NSGregorianCalendar]autorelease];NSDateComponents *comps = [[[NSDateComponentsalloc] init] autorelease];NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;//int week=0;comps = [calendar components:unitFlags fromDate:date];int week = [comps weekday];int year=[comps year];int month = [comps month];int day = [comps day];[formatter setDateStyle:NSDateFormatterMediumStyle];// //This sets the label with the updated time.int hour = [comps hour];int min = [comps minute];int sec = [comps second];
NSLog(@“day%d”,day);NSLog(@“hour%d”,hour);NSLog(@“min%d”,min);NSLog(@“sec%d”,sec);
27、数组中存储数据查询
NSMutableDictionary *userDic1 = [NSMutableDictionary dictionaryWithCapacity:10];NSMutableDictionary *userDic2 = [NSMutableDictionary dictionaryWithCapacity:10];[userDic1 setValue:@“Li” forKey:@“name”];
NSArray *userArray = [NSArray arrayWithObjects:userDic1,userDic2,nil];NSPredicate *namePredicate = [NSPredicate predicateWithFormat:@“SELF.name contains[cd] %@ ”,@“L”];
NSMutableArray *searchArray = [NSMutableArray arrayWithArray:[userArray filteredArrayUsingPredicate:namePredicate]];
NSLog(@“searchArray == %@”,searchArray);
28、CoreText 总结
(1)NSAttributedString NSAttributedString 可以将一段文字中的部分文字设置单独的字体和颜色。与UITouch结合可以实现点击不同文字触发不同事件的交互功能。主要方法:
-(void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range;可以设置某段文字的字体名称,颜色,下滑线等信息。
-(void)removeAttribute:(NSString *)name range:(NSRange)range;移除之前设置的字体属性值。
-(void)addAttributes:(NSDictionary *)attrs range:(NSRange)range;存储某段文字包含的信息(包括字体属性或其它,也可以存储一些自定义的信息)-(NSDictionary *)attributesAtIndex:(NSUInteger)location effectiveRange:(NSRangePointer)range;通过location来获取某段文字中之前存储的信息NSDictionary
//设置字体
CTFontRef aFont = CTFontCreateWithName((CFStringRef)textFont.fontName, textFont.pointSize, NULL);if(!aFont)return;CTFontRef newFont = CTFontCreateCopyWithSymbolicTraits(aFont, 0.0, NULL, kCTFontItalicTrait, kCTFontBoldTrait);//将默认黑体字设置为其它字体 [self removeAttribute:(NSString*)kCTFontAttributeName range:textRange];[self addAttribute:(NSString*)kCTFontAttributeName value:(id)newFont range:textRange];CFRelease(aFont);CFRelease(newFont);
//设置字体颜色
[self removeAttribute:(NSString*)kCTForegroundColorAttributeName range:textRange];[self addAttribute:(NSString*)kCTForegroundColorAttributeName value:(id)textColor.CGColor range:textRange];
//设置对齐 换行
CTTextAlignment coreTextAlign = kCTLeftTextAlignment;CTLineBreakMode coreTextLBMode = kCTLineBreakByCharWrapping;CTParagraphStyleSetting paraStyles[2] = { {.spec = kCTParagraphStyleSpecifierAlignment,.valueSize = sizeof(CTTextAlignment),.value =(const void*)&coreTextAlign}, {.spec = kCTParagraphStyleSpecifierLineBreakMode,.valueSize = sizeof(CTLineBreakMode),.value =(const void*)&coreTextLBMode}, };CTParagraphStyleRef aStyle = CTParagraphStyleCreate(paraStyles, 2);[self removeAttribute:(NSString*)kCTParagraphStyleAttributeName range:textRange];[self addAttribute:(NSString*)kCTParagraphStyleAttributeName value:(id)aStyle range:textRange];CFRelease(aStyle);
(2)Draw NSAttributedString
CGContextRef cgc = UIGraphicsGetCurrentContext();CGContextSaveGState(cgc);
//图像方向转换
CGContextConcatCTM(cgc, CGAffineTransformScale(CGAffineTransformMakeTranslation(0, self.bounds.size.height), 1.f,-1.f));
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)weiBoText);
CGMutablePathRef path = CGPathCreateMutable();CGPathAddRect(path, NULL, drawingRect);textFrame = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,0), path, NULL);CGPathRelease(path);CFRelease(framesetter);
CTFrameDraw(textFrame, cgc);CGContextRestoreGState(cgc);(3)图文混排
CTFrameRef textFrame // coreText 的 frame CTLineRef line // coreText 的 line CTRunRef run // line 中的部分文字 相关方法:
CFArrayRef CTFrameGetLines(CTFrameRef frame)//获取包含CTLineRef的数组 void CTFrameGetLineOrigins(CTFrameRef frame, CFRange range, CGPoint origins[])//获取所有CTLineRef的原点
CFRange CTLineGetStringRange(CTLineRef line)//获取line中文字在整段文字中的Range CFArrayRef CTLineGetGlyphRuns(CTLineRef line)//获取line中包含所有run的数组 CFRange CTRunGetStringRange(CTRunRef run)//获取run在整段文字中的Range CFIndex CTLineGetStringIndexForPosition(CTLineRef line, CGPoint position)//获取点击处position文字在整段文字中的index CGFloat CTLineGetOffsetForStringIndex(CTLineRef line, CFIndex charIndex, CGFloat* secondaryOffset)//获取整段文字中charIndex位置的字符相对line的原点的x值 主要步骤:
1)计算并存储文字中保含的所有表情文字及其Range 2)替换表情文字为指定宽度的NSAttributedString
callbacks.version = kCTRunDelegateVersion1;callbacks.getAscent = ascentCallback;callbacks.getDescent = descentCallback;callbacks.getWidth = widthCallback;callbacks.dealloc = deallocCallback;
CTRunDelegateRef runDelegate = CTRunDelegateCreate(&callbacks, NULL);NSDictionary *attrDictionaryDelegate = [NSDictionary dictionaryWithObjectsAndKeys:(id)runDelegate,(NSString*)kCTRunDelegateAttributeName, [UIColor clearColor].CGColor,(NSString*)kCTForegroundColorAttributeName, nil];
NSAttributedString *faceAttributedString = [[NSAttributedString alloc] initWithString:@“*” attributes:attrDictionaryDelegate];
[weiBoText replaceCharactersInRange:faceRange withAttributedString:faceAttributedString];[faceAttributedString release];3)根据保存的表情文字的Range计算表情图片的Frame textFrame 通过CTFrameGetLines 获取所有line的数组 lineArray 遍历lineArray中的line通过CTLineGetGlyphRuns获取line中包含run的数组 runArray 遍历runArray中的run 通过CTRunGetStringRange获取run的Range 判断表情文字的location是否在run的Range 如果在 通过CTLineGetOffsetForStringIndex获取x的值 y的值为line原点的值 4)Draw表情图片到计算获取到的Frame
(3)点击文字触发事件
主要步骤:
1)根据touch事件获取点point 2)textFrame 通过CTFrameGetLineOrigins获取所有line的原点 3)比较point和line原点的y值获取点击处于哪个line 4)line、point 通过CTLineGetStringIndexForPosition获取到点击字符在整段文字中的 index
5)NSAttributedString 通过index 用方法-(NSDictionary *)attributesAtIndex:(NSUInteger)location effectiveRange:(NSRangePointer)range 可以获取到点击到的NSAttributedString中存储的NSDictionary 6)通过NSDictionary中存储的信息判断点击的哪种文字类型分别处理
一、判断题(每题2分,共20分)1、UITableView能够绑定多个数据源。(错)2、一个UIViewController可以管理多个UITableView。(对)3、Object-c的类可以多重继承。(错)4、objective-c类里面......
www.daodoc.com美国上市公司亿元级外企IT培训企业100个iOS开发/设计程序员面试题汇总无论是对于公司还是开发者或设计师个人而言,面试都是一项耗时耗钱的项目,本文作者Cameron......
刀豆文库小编为你整合推荐5篇ios开发学习心得,也许这些就是您需要的文章,但愿刀豆文库能带给您一些学习、工作上的帮助。......
刀豆文库小编为你整合推荐5篇ios程序员实习报告,也许这些就是您需要的文章,但愿刀豆文库能带给您一些学习、工作上的帮助。......
刀豆文库小编为你整合推荐7篇ios程序员年终工作总结,也许这些就是您需要的文章,但愿刀豆文库能带给您一些学习、工作上的帮助。......
