IOS开发小问题

来源:互联网 发布:powerdvd是什么软件 编辑:程序博客网 时间:2024/05/16 17:25
新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)
            {
                gotoCancelBlock;
            }
             
            //例如:下面是你block中实际任务中的一步
            [NSThreadsleepForTimeInterval:1.0];
            NSLog(@"%@ Simulator: Job step costs 1 second ", [NSDate date]);
             
             
            //推荐:block中每完成一个重要步骤后都,立即检查是否需要退出,这样才能达到立即结束任务的作用
            if(_shouldStop)
            {
                gotoCancelBlock;
            }
            //例如:又完成了一部分操作
            [NSThreadsleepForTimeInterval:3.0];
            NSLog(@"%@ Simulator: Job step costs 3 second ", [NSDate date]);
             
            //又检查是否需要退出
            if(_shouldStop)
            {
                gotoCancelBlock;
            }
            [NSThreadsleepForTimeInterval: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字数过多时的显示方式

  1. lineBreakMode:设置标签文字过长时的显示方式。   
  2. label.lineBreakMode = NSLineBreakByCharWrapping;    //以字符为显示单位显示,后面部分省略不显示。   
  3. label.lineBreakMode = NSLineBreakByClipping;        //剪切与文本宽度相同的内容长度,后半部分被删除。   
  4. label.lineBreakMode = NSLineBreakByTruncatingHead;  //前面部分文字以……方式省略,显示尾部文字内容。   
  5. label.lineBreakMode = NSLineBreakByTruncatingMiddle;    //中间的内容以……方式省略,显示头尾的文字内容。   
  6. label.lineBreakMode = NSLineBreakByTruncatingTail;  //结尾部分的内容以……方式省略,显示头的文字内容。   
  7. label.lineBreakMode = NSLineBreakByWordWrapping;    //以单词为显示单位显示,后面部分省略不显示。 
6.快捷键
commend_shift+o快速搜索

7.

今天OS X 10.9 Mavericks正式发布,免费更新,立即去更新看看效果。

不过升级后安装命令行工具(Command Line Tools)时发现官网没有clt的下载安装包了,原来改了,使用命令在线安装。

打开终端,输入命令:xcode-select --install
8.提示小心定时消失

/**

 *  展示提示并且定时消失

 *

 *  @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];

    }];

    

}

9.

//  设置行间距

- (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];
11.导航栏背景色:barTintColor
12.html5和iOS交互
//    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]];

0 0
原创粉丝点击