分类 IOS 中的文章

app 与 服务器 交互

step1封装post数据 //请求地址 NSString *url = [NSString stringWithFormat:@"%@%@", [PKConfig apiUrl], service]; PKLog(@"请求地址是 %@",url); //时间戳 long long timestamp = [[NSDate date] timeIntervalSince1970]; NSString *timestampStr = [NSString stringWithFormat:@"%lld", timestamp]; //参数 NSMutableDictionary *parameters = [[NSMutableDictionary alloc] init]; NSData *postData = nil; if(type!=1){ // Service [parameters setObject:service forKey:@"service"]; // ID [parameters setObject:timestampStr forKey:@"id"]; // Common NSMutableDictionary *commonDict = [[NSMutableDictionary alloc] init]; [commonDict setObject:@([PKConfig vc]) forKey:@"vc"]; [commonDict setObject:[PKConfig vn] forKey:@"vn"]; [commonDict setObject:@"1" forKey:@"build"]; [commonDict setObject:[PKConfig uuid] forKey:@"uuid"]; [commonDict setObject:[PKConfig imei] forKey:@"imei"]; [commonDict setValue:[PKConfig os] forKey:@"os"]; [commonDict setObject:[PKConfig ch] forKey:@"ch"]; [commonDict setObject:[PKConfig osSdk] forKey:@"osSdk"]; [commonDict setObject:[PKConfig caller] forKey:@"caller"]; [parameters setObject:commonDict forKey:@"common"]; // Param [parameters setObject:paramDict forKey:@"param"]; //……

阅读全文

UitextView的动态调整

根据字体和设定宽度计算高度 //自适应字体 - (CGSize)sizeWithString:(NSString*)string font:(UIFont*)font width:(float)width { CGRect rect = [string boundingRectWithSize:CGSizeMake(width,80000) options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil]; return rect.size; } 限制高度截取内容 //获取字体高度 - (CGFloat)getTextHeight:(NSString*)string{ CGSize size = CGSizeMake(PKScreenW - 32 - 10, MAXFLOAT); CGFloat height; if (string == nil) { height = [@"高" boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil].size.height; } else { height = [string boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingTruncatesLastVisibleLine attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14]} context:nil].size.height; } return height; } //获取指定高度所含字符内容 - (NSString*)getTextWithHeight:(CGFloat)heigth andString:(NSString*) str{ //NSString *str = self.textView.text; NSInteger i = 0 ;……

阅读全文

layoutIfNeeded setNeedsLayout layoutSubviews 区别

layoutSubviews 可按需要重写内部函数 init初始化不会触发layoutSubviews addSubview会触发layoutSubviews 设置view的Frame并发生变化会触发layoutSubviews 滚动一个UIScrollView会触发layoutSubviews 旋转Screen会触……

阅读全文

Masonry 约束框架使用

Masonry第三方约束 (2016.4.14更新) cocospads add file Masonry_github 只使用Masonry文件夹内容 使用cocospad 安装 product -> cocoaPods ->install pods (注意路径) gem_path: /usr/local/bin install 后一等一会 会有输出提示 代码设置 // 只要添加了这个宏,就不用带mas_前缀 #define MAS_SHORTHAND // 只要添加了这个宏,equalTo就等价于mas_equalTo #define……

阅读全文

UIButton,UILabel 控件样式

UIButton btn文字下划线样式 NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"查看所有中奖记录"]; NSRange strRange = {0,[str length]}; [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange]; [self.btn setAttributedTitle:str forState:UIControlStateNormal]; btn边框样式 - (UIButton*)btn{ if (_btn == nil) { UIButton * btn = [[UIButton alloc]init]; // 外边框 btn.layer.masksToBounds = YES; btn.layer.cornerRadius = 2; btn.layer.borderWidth = 1; //btn.layer.borderColor = PKBtnSelectedColor.CGColor; btn.layer.borderColor = [UIColor blueColor].CGColor; // 文字 btn.titleLabel.textAlignment = NSTextAlignmentCenter; //字体大小 btn.titleLabel.font = [UIFont systemFontOfSize: 12.0]; //文字内容 [btn setTitle:@"" forState:UIControlStateNormal]; //消息回调 [btn addTarget:self action:@selector(btnClick)……

阅读全文

网页 交互 框架 js

网页交互框架/() 1初始化 注册moduleAPIs dict 1代码 FDWebViewController初始化时,要顺便把WAUserInterfaceAPI ,WebAppBridge 初始化 代码 - (void)viewDidLoad { self.webView = [[WAWebView alloc] init]; self.webView.moduleAPIs = @[[WADeviceAPI sharedInstance], [[WAUserInterfaceAPI alloc] initWithContext:self], [WAUserAPI sharedInstance]]; } 字典key //self.webView.moduleAPIs _ type is NSMutableArray,val is: [0] (null) @"user" : (no summary) [1] (null) @"device" : (no summary) [2] (null) @"UI" : (no summary) (看情况手工处理) 2其中……

阅读全文

cocoapods XCODE 7.0后版本

1. 参靠资料 最新版 CocoaPods 的安装流程 2. 命令 sudo gem install -n /usr/local/bin cocoapods 3. 编译文件 cocoapods 4. 重启XCODE……

阅读全文

scrollview的contentSize、contentInset和contentOffset区别

而contentSize、contentInset和contentOffset 是 scrollView三个基本的属性。 contentSize: The size of the content view. 其实就是scrollview可以滚动的区域,比如frame = (0 ,0 ,320 ,480) contentSize = (320 ,960),代表你的scrollview可以上下滚动,滚动区域为frame大……

阅读全文