
iOS
Johnay_xiao
Stay hungry, Stay foolish!
展开
-
iOS 将json文件转为plist文件
NSString *path = [[NSBundle mainBundle] pathForResource:@"address.json" ofType:nil]; NSLog(@"path = %@",path); NSArray *array = [NSJSONSerialization JSONObjectWithData:[NSData dataWithContentsOf原创 2017-07-24 08:41:57 · 1729 阅读 · 0 评论 -
AFN用Post发送Json数据
NSDictionary * arr = @{ @"userName":@"408131213@qq.com", @"passWord":@"111111", @"longitudes":@"changsha",原创 2016-10-17 15:46:38 · 1850 阅读 · 0 评论 -
解决tableView无数据时还显示横线及线条显示不全问题
//解决tableView无数据时还显示横线问题 UIView *v = [[UIView alloc] initWithFrame:CGRectZero]; [self.tableView setTableFooterView:v];//解决cell线条显示不全-(void)viewDidLayoutSubviews { if ([self.tableView respo原创 2016-11-07 17:02:52 · 2891 阅读 · 0 评论 -
安装CocoaPods报错,The dependency AFNetworking (~> 3.1.0) is not used in any concrete target
安装CocoaPods报错:[!] The dependency AFNetworking (~> 3.1.0) is not used in any concrete target. 今天新机装cocopods时,等安装完毕发觉出现[!] The dependency AFNetworking (~> 3.1.0) is not used in any concrete target.这个警告。原创 2016-10-17 09:42:24 · 1234 阅读 · 0 评论 -
UIImage图片转成Base64字符串
//UIImage图片转成Base64字符串:UIImage *originImage = [UIImage imageNamed:@"originImage.png"];NSData *data = UIImageJPEGRepresentation(originImage, 1.0f);NSString *encodedImageStr = [data base64EncodedStrin原创 2016-11-04 11:59:01 · 899 阅读 · 0 评论 -
AVPlayerLayer播放网络音视频
#import "ViewController.h"#import <AVFoundation/AVFoundation.h>@interface ViewController ()@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentControl;//播放对象@property (nonatomic, strong原创 2016-10-12 15:00:04 · 2009 阅读 · 0 评论 -
AVAudioPlayer播放本地音频
#import "ViewController.h"#import <AVFoundation/AVFoundation.h>@interface ViewController ()//记录systemSoundID@property (nonatomic, assign) SystemSoundID systemID;//记录播放器对象@property (nonatomic, stro原创 2016-10-12 14:56:02 · 436 阅读 · 0 评论 -
MKMapView绘制路线
#import "ViewController.h"#import <MapKit/MapKit.h>@interface ViewController ()<MKMapViewDelegate>@property (weak, nonatomic) IBOutlet MKMapView *mapView;@property (nonatomic, strong) CLGeocoder *ge原创 2016-10-12 14:40:33 · 738 阅读 · 0 评论 -
MKMapView的Annotation使用
#import "ViewController.h"#import <MapKit/MapKit.h>#import "TRAnnotation.h"@interface ViewController ()<MKMapViewDelegate>@property (weak, nonatomic) IBOutlet MKMapView *mapView;@property (nonatomi原创 2016-10-12 14:38:12 · 780 阅读 · 0 评论 -
MKMapView使用
#import "ViewController.h"#import <MapKit/MapKit.h>@interface ViewController ()<MKMapViewDelegate>@property (weak, nonatomic) IBOutlet MKMapView *mapView;@property (nonatomic, strong) CLLocationMana原创 2016-10-12 14:25:00 · 368 阅读 · 0 评论 -
CoreLocation定位
#import "ViewController.h"#import <CoreLocation/CoreLocation.h>@interface ViewController ()<CLLocationManagerDelegate>//必须把CLLocationManger声明属性@property (nonatomic, strong) CLLocationManager *mgr;@en原创 2016-10-12 14:20:10 · 256 阅读 · 0 评论 -
NSJSONSerialization使用
- (IBAction)convertJSON2Foundation:(id)sender { //需求:从网络中请求天气的JSON数据, 解析指定的值,显示到textView上 //0.天气对应url NSURL *weatherURL = [NSURL URLWithString:@"http://www.raywenderlich.com/demos/weather_s原创 2016-10-12 11:30:52 · 545 阅读 · 0 评论 -
Json本地解析
- (void)viewDidLoad { [super viewDidLoad]; //1.获取文件的路径 NSString *jsonFilePath = [[NSBundle mainBundle] pathForResource:@"test.json" ofType:nil]; //2.读取文件内的数据(NSData类型:一般服务器返回的数据类型是NSData原创 2016-10-12 11:17:04 · 254 阅读 · 0 评论 -
AFNetworking发送get和post请求
#import "ViewController.h"#import "AFNetworking.h"@interface ViewController ()@end@implementation ViewController- (IBAction)sendHTTPGetRequest:(id)sender { //0.准备url的字符串 NSString *urlStr = @"h原创 2016-10-12 11:10:58 · 388 阅读 · 0 评论 -
NSURLSessionDownloadTask下载图片
#import "ViewController.h"@interface ViewController ()<NSURLSessionDownloadDelegate>//显示进度label@property (weak, nonatomic) IBOutlet UILabel *progressPercentLabel;//进度视图@property (weak, nonatomic) I原创 2016-10-12 11:00:53 · 845 阅读 · 0 评论 -
URLSession数据协议下载图片
#import "ViewController.h"@interface ViewController ()<NSURLSessionDataDelegate>@property (weak, nonatomic) IBOutlet UIImageView *imageView;@property (weak, nonatomic) IBOutlet UIProgressView *progre原创 2016-10-12 10:40:41 · 416 阅读 · 0 评论 -
通知的使用方法
1.注册通知[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showProgressHud:) name:@"showProgressHud" object:nil];2.发送通知[[NSNotificationCenter defaultCenter] postNotificationName:@"原创 2016-10-10 14:14:16 · 259 阅读 · 0 评论 -
iOS开发中获取短信验证码倒计时按钮的实现
-(void)startTime{ __block int timeout=59; //倒计时时间 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t _timer = dispatch_source_create(D原创 2016-11-17 17:31:03 · 354 阅读 · 0 评论 -
iOS UIImage生成高性能圆角图片
- (void)imageWihtSize:(CGSize)size radius:(CGFloat)radius backColor:(UIColor *)backColor completion:(void(^)(UIImage *image))completion{ // 异步绘制裁切 dispatch_async(dispatch_get_global_queue(0, 0)原创 2017-11-27 11:19:15 · 1026 阅读 · 0 评论 -
iOS 版本检测更新
#pragma mark - 检查更新- (void)checkVersion{ if ([AppID length] < 1) { return; } NSString *url = [NSString stringWithFormat:@"http://itunes.apple.com/lookup?id=%@",AppID]; NSMutabl原创 2017-11-15 10:02:44 · 757 阅读 · 0 评论 -
WKWebView内容自适应宽度
NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appe原创 2017-11-13 15:36:27 · 4008 阅读 · 1 评论 -
UIWebView&WKWebView获取网页高度
实测,必需要延迟一会儿才能获取正确高度。 -(void)webViewDidFinishLoad:(UIWebView *)webView { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ CGFloat原创 2017-11-09 17:27:46 · 256 阅读 · 0 评论 -
UIDocumentInteractionController 的使用
//// ViewController.m// pdfViewer//// Created by Johnay on 17/9/28.// Copyright © 2017年 Johnay. All rights reserved.//#import "ViewController.h"@interface ViewController ()<UIDocumentInterac原创 2017-09-30 15:10:55 · 980 阅读 · 0 评论 -
一个iOS程序员自己写代码将Kindle中我的剪贴内容筛选提取出来
//// ViewController.m// readFile//// Created by Johnay on 17/8/22.// Copyright © 2017年 Johnay. All rights reserved.//#import "ViewController.h"@interface ViewController ()<UIScrollViewDelega原创 2017-08-22 11:33:19 · 443 阅读 · 0 评论 -
iOS 控制textField只能输入指定字符
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([textField == yourTextField) { if (![self validateNumber:str原创 2017-08-25 11:35:16 · 385 阅读 · 0 评论 -
iOS 精确控制textField输入的小数位数
直接在代理方法中写代码- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (textField == yourTextField) { NSString * toBeStri原创 2017-08-25 11:30:46 · 388 阅读 · 0 评论 -
iOS 正则表达式判断3个正数相乘
#import "ViewController.h"#import "AFNetworking.h"@interface ViewController (){ UITextField *textF;}@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; textF =原创 2017-08-14 10:47:22 · 501 阅读 · 0 评论 -
iOS 防止UIButton按钮重复点击
- (void)viewDidLoad{ [super viewDidLoad]; // 1. 创建 btn 并添加点击事件 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; [btn setFrame:CGRectMake(100, 100, 100, 60)]; btn.backgro原创 2017-08-10 10:06:48 · 329 阅读 · 0 评论 -
iOS 解决打包上传报This action could not be completed. Try again. (-22421)问题
终端执行三条命令完美解决尊重原创者劳动成果哈cd ~ mv .itmstransporter/ .old_itmstransporter/ “/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/itms/bin/iTMSTransporter” 注意:一定要等第三条命令执行完毕才可以原创 2017-05-11 14:41:49 · 8662 阅读 · 17 评论 -
iOS开发自动检测内存泄漏神器MLeaksFinder
给大家介绍一个内存检测神器,只需要用cocoaPods安装,无需导入任何头文件即可自动检测内存泄漏。GitHub地址 https://github.com/Zepo/MLeaksFindercocoaPods安装代码:pod ‘MLeaksFinder’安装后效果如下:最后如果想关闭自动检测功能,只需要将MLeaksFinder.h文件中第11行注释去掉即可!原创 2017-07-25 11:16:45 · 2484 阅读 · 0 评论 -
UIImage 颜色渲染imageWithRenderingMode
UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(100,200,100,100];imgV.image = [[UIImage imageNamed:@"多边形-1"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];imgV.tintColo原创 2017-08-16 11:46:22 · 313 阅读 · 0 评论 -
iOS 使用UIPickerView三级联动实现选择日期年月日
这里面有很多自定义的宏,效果图在下面,如果想要这个效果的朋友,不妨花几分钟把里面的宏改下等不报错了,直接用这下面的代码调用就可以了! 调用代码 SelectTimeV *selectTimeV = [[SelectTimeV alloc] init]; selectTimeV.block = ^(NSString *timeStr) { if (timeStr)原创 2017-07-24 17:16:15 · 9022 阅读 · 2 评论 -
iOS 任意布局UIButton中的图片与文字
- (void)setup{ self.titleLabel.textAlignment = NSTextAlignmentCenter;}- (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self setup]; } r原创 2017-07-24 16:37:33 · 440 阅读 · 0 评论 -
GCD实现下载图片操作
#import "TRTableViewController.h"#import "TRDataManager.h"#import "TRAlbum.h"#import "TRTableViewCell.h"@interface TRTableViewController ()@property (nonatomic, strong) NSArray *albumsArray;//存储下载好原创 2016-10-12 10:32:24 · 323 阅读 · 0 评论 -
WKWebView使用
#import "ViewController.h"#import <WebKit/WebKit.h>@interface ViewController ()<WKNavigationDelegate>@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; //1.创建NSURL原创 2016-10-12 10:05:15 · 291 阅读 · 0 评论 -
iOS文件读写
- (void)viewDidLoad { [super viewDidLoad]; //需求:NSArray数据存到XXX/Documents/test.txt //1.NSArray NSArray *array = @[@"Jonny", @19, @[@"Objective-C", @"Swift", @"Ruby"]]; //2.Documents路原创 2016-10-11 14:02:03 · 326 阅读 · 0 评论 -
获取沙盒路径
//1.获取沙盒数据容器根目录 NSString *homePath = NSHomeDirectory(); NSLog(@"home根目录:%@", homePath); //2.获取Documents路径 /*参数一:指定要搜索的文件夹枚举值 参数二:指定搜索的域Domian: NSUserDomainMask 参数三:是否需要绝对/全路原创 2016-10-11 13:59:07 · 362 阅读 · 0 评论 -
iOS代码行数计算
import <Foundation/Foundation.h>//存放文件绝对路径NSString *filePath = @"/Users/ios/Desktop/dome-3";// 计算文件的代码行数/* path : 文件的全路径(可能是文件夹、也可能是文件) 返回值 int :代码行数 */NSUInteger codeLineCount(NSString *path){原创 2016-10-11 09:59:29 · 301 阅读 · 0 评论 -
沙盒读写
- 写[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@”isFirstLaunch”]; [[NSUserDefaults standardUserDefaults] synchronize];- 读BOOL launchScreen = [[NSUserDefaults standardUserDefaults原创 2016-10-10 16:30:04 · 248 阅读 · 0 评论 -
导航栏添加自定义按钮(图片在左文字在右)
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom]; addButton.frame = CGRectMake(10, 0, 60, 40); [addButton setImage:[UIImage imageNamed:@"iconfont-xinzengyemian"] forState:UICo原创 2016-10-10 14:39:21 · 2651 阅读 · 0 评论