• 一些你可能用到的代码


    iPhone键盘改变颜色

    只有这2种数字键盘才有效果:UIKeyboardTypeNumberPad,UIKeyboardTypePhonePad
    keyboardAppearance = UIKeyboardAppearanceAlert 
    代码如下:

    NSArray *ws = [[UIApplication sharedApplication] windows];
        for(UIView *w in ws){
            NSArray *vs = [w subviews];
            for(UIView *v in vs){
               if([[NSStringstringWithUTF8String:object_getClassName(v)]isEqualToString:@"UIKeyboard"]){
                    v.backgroundColor = [UIColor redColor];
                }
            }
        }

    从一个界面push到下一界面左上角返回按钮文字设置

    在父viewController中如下设置:

    UIBarButtonItem *backbutton = [[UIBarButtonItem alloc]init];
    backbutton.title = @"返回列表";
    self.navigationItem.backBarButtonItem = backbutton;

    防止屏幕暗掉锁屏:

    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];

    navigationbar的back键触发其他事件:

    UIButton *back =[[UIButton alloc] initWithFrame:CGRectMake(200, 25, 63, 30)];
    [back addTarget:self act
    ion:@selector(reloadRowData:) forControlEvents:UIControlEventTouchUpInside];
    [back setImage:[UIImage imageNamed:@"返回按钮.png"] forState:UIControlStateNormal];
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = loginButtonItem;

    让覆盖在下面层的视图接受触摸事件:

    searchImage.exclusiveTouch = YES;//第一层
    searchImage.userInteractionEnabled = NO;
    myMapView.exclusiveTouch = NO;//第二层
    myMapView.userInteractionEnabled = YES;

    View的缩放

    NSValue *touchPointValue = [[NSValue valueWithCGPoint:CGPointMake(100,100)] retain];
    [UIView beginAnimations:nil context:touchPointValue];
    transform = CGAffineTransformMakeScale(0.1,0.21);
    firstPieceView.transform = transform;
    [UIView commitAnimations]; 

    去除nsstring中的空格,table 以及newline,nextline:

    NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    NSString *username = [mUsernameField stringValue];
    username = [username stringByTrimmingCharactersInSet:whitespace];

    WebView:
    CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0); 
    UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame]; 
    [webView setBackgroundColor:[UIColor whiteColor]]; 
    NSString *urlAddress = @"http://www.google.com"; 
    NSURL *url = [NSURL URLWithString:urlAddress];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
    [webView loadRequest:requestObj];
    [self addSubview:webView];

    UILabel 自适应高度,自动换行

    _labelName = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, IPHONE_BUTTON_WIDTH, 1000)];
            [_labelName setFont:[UIFont boldSystemFontOfSize:25]];
            [_labelName setTextColor:[UIColor whiteColor]];
            [_labelName setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.6f]];
            [_labelName setNumberOfLines:0];
            [_labelName setText:NSLocalizedString(@"nameLabel", @"……")];
            [_labelName sizeToFit];
            [_labelName setFrame:CGRectMake(0, 0, IPHONE_BUTTON_WIDTH, _labelName.frame.size.height)];

    一些你可能用到的代码链接:http://www.cnblogs.com/dark-angel/archive/2011/07/05/2098087.html

    代码例子区全区搜索索引:http://www.cocoachina.com/bbs/read.php?tid=12269

  • 相关阅读:
    程序员的自我修养(序)-量子
    我的IT生活-量子
    量子地图
    再出发
    新的一年快开始了,学点新东西吧,从React开始(一)
    ECMAScript 6 Features 中文版
    必须清零
    彩印网的第一阶段即将收官
    终于感觉掌握了一门重要的技术
    程序员的命运之轮
  • 原文地址:https://www.cnblogs.com/pengoeng/p/4792326.html
Copyright © 2020-2023  润新知