美文网首页
iOS开发细节

iOS开发细节

作者: anyurchao | 来源:发表于2015-11-29 19:32 被阅读681次

解决有的图片显示时只是一块颜色,而显示不正常的问题

//渲染UIImage*image = [UIImageimageNamed:@"imageName"];image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

毛玻璃效果

UIImageView*imageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"xiaoxin3"]];//毛玻璃效果UIVisualEffectView*visualView = [[UIVisualEffectViewalloc]initWithEffect:[UIBlurEffecteffectWithStyle:(UIBlurEffectStyleLight)]];visualView.frame=self.tableView.bounds;visualView.alpha=0.8;[imageView addSubview:visualView];self.tableView.backgroundView= imageView;

视图截圆角

_customView.layer.masksToBounds = YES;_customView.layer.cornerRadius =    self.customView.bounds.size.width/2;

使用NSURLSession请求网络数据

//通过单例创建Session对象//步骤1.NSURLSession 服务器数据异步加载,作用和NSURLConnection的作用相同NSURLSession*session = [NSURLSessionsharedSession];//步骤2.封装网络请求NSURLRequest*request = [[NSURLRequestalloc] initWithURL:[NSURLURLWithString:@"baidu.com"]];//步骤3.准备加载数据,创建这个任务的taskNSURLSessionTask*task = [session dataTaskWithRequest:request completionHandler:^(NSData* _Nullable data,NSURLResponse* _Nullable response,NSError* _Nullable error) {//当加载数据完成时,调用该blockNSLog(@"%@",data);//手动解析网络数据NSDictionary*dict = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:nil];NSLog(@"%@",data);}];//调用此方法开始加载数据[task resume];

播放语音

//导入包import //声音集成器AVSpeechSynthesizer*speechSy = [[AVSpeechSynthesizeralloc] init];//发声器AVSpeechUtterance*utterance = [[AVSpeechUtterancealloc] initWithString:@"i am very happy"];AVSpeechUtterance*utterance2 = [[AVSpeechUtterancealloc] initWithString:@"ha ha ha"];AVSpeechUtterance*utterance3 = [[AVSpeechUtterancealloc] initWithString:_textFeild.text];//给合成器添加发生器,让其发音[speechSy speakUtterance:utterance];[speechSy speakUtterance:utterance2];[speechSy speakUtterance:utterance3];//哪国语言utterance.voice= [AVSpeechSynthesisVoicevoiceWithLanguage:@"en-US"];//语速utterance.rate=0.5;//音高utterance.pitchMultiplier=1.0;

webView

UIWebView*webView = [[UIWebViewalloc]  initWithFrame:self.view.frame];[webView loadRequest:[NSURLRequestrequestWithURL:[NSURLURLWithString:myurl]]];self.view= webView;

使用第三方SDWevImage解析图片

[cell.imgViewsd_setImageWithURL:[NSURLURLWithString:news.picUrl]placeholderImage:[UIImageimageNamed:@"image"]];

设置cell的自适应高度

使用此方法必须要设置cell中的最后一个控件与cell的距离

self.myTableView.rowHeight=UITableViewAutomaticDimension;self.myTableView.estimatedRowHeight=100;

让音乐在后台播放

[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlaybackerror:nil];

将URL中的汉字转换成utf-8格式,拼接到URL字符串中

NSString*typeString = (__bridgeNSString*)CFURLCreateStringByAddingPercentEscapes(NULL,(__bridgeCFStringRef)@"健康",NULL,(CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8);

去除解析出来的数据带的 HTML 标记

- (NSString *)filterHTML:(NSString *)html{NSScanner * scanner = [NSScannerscannerWithString:html];NSString * text = nil;while([scanner isAtEnd]==NO){//找到标签的起始位置[scannerscanUpToString:@"<"intoString:nil];//找到标签的结束位置[scannerscanUpToString:@">"intoString:&text];//替换字符html = [htmlstringByReplacingOccurrencesOfString:[NSStringstringWithFormat:@"%@>",text]withString:@""];}returnhtml;}

去广告

先到网页,找到开发者平台,依次输入并提交

document.getElementsByClassName(‘index_mask’) ->

document.getElementsByClassName(‘index_mask’)[0] ->

document.getElementsByClassName(‘index_mask’[0].style.display = ‘none’

若在网页上显示的对应的广告没了,就可以将最后一句写到下面的程序中

-(void)webViewDidFinishLoad:(UIWebView *)webView{[webViewstringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('index_mask')[0].style.display = 'none'"];}

图片自适应

imgView.contentMode = UIViewContentModeScaleAspectFit;

解决tableView的head不会和cell一起滚动的问题

self.tableView= [[UITableViewalloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height) style:UITableViewStyleGrouped];

解决有navigationbar的情况下,下面的tableView与navigationbar有一段距离的问题

self.automaticallyAdjustsScrollViewInsets=NO;

数据再cell中解析,给cell做自适应高度时,无法实现

可能是因为cell出现时,自适应高度已经实现了,但是还没有内容,所以想办法先刷新一下数据(使用block块可以在cellForRow……方法中实现)

相关文章

  • iOS开发 UITableView 常用细节

    iOS开发 UITableView 常用细节 iOS开发 UITableView 常用细节

  • iOS开发细节

    解决有的图片显示时只是一块颜色,而显示不正常的问题 //渲染UIImage*image = [UIImageima...

  • iOS开发证书要点详解

    转自 iOS开发证书要点详解,ios证书详解 有细节修改。 首先,假设你使用过Apple设备(iMac/iPad/...

  • iOS开发小细节

    1.http 网络连接 1.在Info.plist中添加 App Transport Security Sett...

  • iOS开发常用细节

    前言 github:https://github.com/koknine (求star,follow ^_^) 之...

  • iOS开发细节记录

    UITapGestureRecognizer单击和双击事件响应 如果tap事件定义在同一个地方的通用方法是下面: ...

  • iOS上的include --- PlaceHolderV

    前言 小弟从事移动开发,从Android入门,再兼做iOS,总的来说Android和iOS的思路是相同的,但细节上...

  • ios 多重复项目开发(Blog)

    前言 本人今年主要在负责猿题库 iOS 客户端的开发,本文旨在通过分享猿题库 iOS 客户端开发过程中的技术细节,...

  • iOS开发细节知识总结

    1.开发中碰到self.navigationController?.pushViewController(sear...

  • iOS widget控件开发细节

    iOS 8开始, 苹果公司推出了today widget. 用来方便用户查看各个app的个性消息. 去github...

网友评论

      本文标题:iOS开发细节

      本文链接:https://www.haomeiwen.com/subject/oiqjhttx.html