新QQ交流群:418536818,之前的群已满
1.“specifies device capability requirements, which are not met by xxx"
遇到此种情况,请查看info.plist文件中的UIRequiredDeviceCapabilities段,确保该段下指定的设备能力都能够被使用的设备所支持。
2.iphone 屏幕尺寸[[UIScreen mainScreen] bounds] 和[UIScreen mainScreen] applicationFrame]
其中[[UIScreen mainScreen] bounds]指整个屏幕的尺寸后面的则是可用的一般是高度减去20,
下面所指的都是[[UIScreen mainScreen] bounds]尺寸
iphone6 高:667宽:375
iphone6plus高736宽:414
iphone5s高568宽320
iphone4s高480宽320
3,终止线程
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(
void
){
/*
* 注意:这里只是用while(YES) 模拟长时间的操作.
*/
while (
YES
)
{
if
(_shouldStop)
{
goto
CancelBlock;
}
//例如:下面是你block中实际任务中的一步
[
NSThread
sleepForTimeInterval:1.0];
NSLog
(@
"%@ Simulator: Job step costs 1 second "
, [
NSDate
date]);
//推荐:block中每完成一个重要步骤后都,立即检查是否需要退出,这样才能达到立即结束任务的作用
if
(_shouldStop)
{
goto
CancelBlock;
}
//例如:又完成了一部分操作
[
NSThread
sleepForTimeInterval:3.0];
NSLog
(@
"%@ Simulator: Job step costs 3 second "
, [
NSDate
date]);
//又检查是否需要退出
if
(_shouldStop)
{
goto
CancelBlock;
}
[
NSThread
sleepForTimeInterval:0.5];
NSLog
(@
"%@ Simulator: Job step costs 0.5 second "
, [
NSDate
date]);
}
/*
* 如果你检查是否需要退出的操作很频繁的话,用个goto语句可以减少很多重复代码
*/
CancelBlock:
//Do some clean up operations here
NSLog
(@
"Block is cancelled"
);
return
;
});
4.获取设置中是否允许推送
//ios7系统
[[UIApplicationsharedApplication]enabledRemoteNotificationTypes] ==0 //不能接收推送,不为0时可以接收推送,是个枚举型
//ios8以上系统
[[UIApplicationsharedApplication]currentUserNotificationSettings].types ==0
//不能接收推送,不为0时可以接收推送,是个枚举型
打印:You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
需要在Xcode 中修改应用的 Capabilities 开启Remote notifications
5.UILabel字数过多时的显示方式
- lineBreakMode:设置标签文字过长时的显示方式。
- label.lineBreakMode = NSLineBreakByCharWrapping; //以字符为显示单位显示,后面部分省略不显示。
- label.lineBreakMode = NSLineBreakByClipping; //剪切与文本宽度相同的内容长度,后半部分被删除。
- label.lineBreakMode = NSLineBreakByTruncatingHead; //前面部分文字以……方式省略,显示尾部文字内容。
- label.lineBreakMode = NSLineBreakByTruncatingMiddle; //中间的内容以……方式省略,显示头尾的文字内容。
- label.lineBreakMode = NSLineBreakByTruncatingTail; //结尾部分的内容以……方式省略,显示头的文字内容。
- label.lineBreakMode = NSLineBreakByWordWrapping; //以单词为显示单位显示,后面部分省略不显示。
commend_shift+o快速搜索
7.
今天OS X 10.9 Mavericks正式发布,免费更新,立即去更新看看效果。
不过升级后安装命令行工具(Command Line Tools)时发现官网没有clt的下载安装包了,原来改了,使用命令在线安装。
打开终端,输入命令:xcode-select --install/**
* 展示提示并且定时消失
*
* @param message 消息内容
* @param time 消息展示时间
*/
-(void)showMessage:(NSString *)message delay:(float)time
{
UIWindow * window = [UIApplicationsharedApplication].keyWindow;
UIView *showview = [[UIViewalloc]init];
showview.backgroundColor = [UIColorblackColor];
showview.frame =CGRectMake(1,1,1,1);
showview.alpha =1.0f;
showview.layer.cornerRadius =5.0f;
showview.layer.masksToBounds =YES;
[windowaddSubview:showview];
UILabel *label = [[UILabelalloc]init];
CGSize LabelSize = [messagesizeWithFont:[UIFontsystemFontOfSize:17]constrainedToSize:CGSizeMake(winsizeW -20, 9000)];
label.frame =CGRectMake(10,5, LabelSize.width, LabelSize.height);
label.text = message;
label.textColor = [UIColorwhiteColor];
label.textAlignment =NSTextAlignmentCenter;
label.backgroundColor = [UIColorlightGrayColor];
label.font = [UIFontboldSystemFontOfSize:15];
[showviewaddSubview:label];
showview.frame =CGRectMake((winsizeW - LabelSize.width -20)/2, (winsizeH - LabelSize.height) /2, LabelSize.width+20, LabelSize.height+10);
[UIViewanimateWithDuration:timeanimations:^{
showview.alpha =0;
}completion:^(BOOL finished) {
[showviewremoveFromSuperview];
}];
}
// 设置行间距
- (void)setLineSpacing:(CGFloat)spacing label:(UILabel *)label
{
NSMutableAttributedString * attributedString = [[NSMutableAttributedStringalloc]initWithString:label.text];
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStylealloc]init];
[paragraphStylesetLineSpacing:spacing];
[attributedStringaddAttribute:NSParagraphStyleAttributeNamevalue:paragraphStylerange:NSMakeRange(0, [label.textlength])];
[labelsetAttributedText:attributedString];
[labelsizeToFit];
}
10.//连接中含有中文
由于url支持26个英文字母、数字和少数几个特殊字符,因此,对于url中包含非标准url的字符时,就需要对其进行编码。iOS中提供了函数stringByAddingPercentEscapesUsingEncoding对中文和一些特殊字符进行编码,但是stringByAddingPercentEscapesUsingEncoding的功能并不完善,对一些较为特殊的字符无效。而对这些字符则可以使用CFURLCreateStringByteAddingPercentEscapes函数,
1 NSString *str = [NSString stringWithUTF8String:surl.c_str()];
2 str = @"http://218.21.213.10/MobileOA/TIFF/鄂安办发45号关于下达2012年全市安全生产相对控制指标的通知1.jpg";
3 str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// JSContext *context=[webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
// NSString *alertJS=@"var tmp=getTest1(); alert(tmp)"; //准备执行的js代码
// NSString *str1= [context evaluateScript:alertJS];//通过oc方法调用js的alert
// 对于调用js的时候最好这个方法里面或者之后
count = [mWebView stringByEvaluatingJavaScriptFromString:@"getCountForIos()"];
if ([count isEqualToString:@"0"]) {
[editButton removeFromSuperview];
self.navigationItem.rightBarButtonItem = nil;
}else{
}
13.iOS导航栏去掉下面黑线
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];