• iPhone开发部分总结(转)


    1.取字符串中的某段字符串 
    [plain] view plaincopyprint? 
    NSString *str =@"12sadfsdf56afsdf";   
    NSLog(@"
    %@",str); 
    NSString *thrStr = [strstringByReplacingOccurrencesOfString:@"56"withString:@"88"];
    NSLog(@"
    %@",thrStr); 
    即把12sadfsdf56afsdf中的56替换为88,替换后字符串为:12sadfsdf88afsdf


    2.简单plist获取
    [plain] view plaincopyprint? 
    NSString *path = [[NSBundlemainBundle]pathForResource:@"Array"ofType:@"plist"];  
    NSMutableDictionary *data = [[NSMutableDictionaryalloc]initWithContentsOfFile:path];  
    NSLog(@"%d",[datacount]);  
    NSLog(@"%@",[dataallValues]);  
    NSLog(@"------------") ;   
    NSArray *ary = [dataallKeys]; 
    NSLog(@"%d",[arycount]); 
    NSArray *array = [NSArrayarrayWithArray:ary];   
    for(int i=0;i<[arraycount];i++)   
    {   
        NSLog(@"\n value = %@",[arrayobjectAtIndex:i]);    
    }   
    NSArray *getArray = [[dataallValues]objectAtIndex:5];

    NSLog(@"get_array:%@",getArray);  
     
    3.状态栏和UINavigationBar设置成透明 
    [[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleBlackTranslucent];  //状态栏设置为透明 
    theNavigationController.navigationBar.barStyle =UIBarStyleBlackTranslucent;   //设置navigationBar为透明

      
    4.设置object圆角,如UIView、UIImageView等 
    简单几步: 
    一.导入QuartzCore.framework框架   #import <QuartzCore/QuartzCore.h>   
    二.object.layer.masksToBounds=YES; 
    三.object.layer.cornerRadius=XXX; 
    [plain] view plaincopyprint? 
    UIImageView *testImageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"1.jpg"]];  
    [testImageViewsetFrame:CGRectMake(20,20,100,100)];  
    testImageView.layer.masksToBounds =YES;   
    testImageView.layer.cornerRadius =50/2;   //设置的角度,改变查看效果   
    testImageView.layer.borderWidth =5;   //边框宽度   
    testImageView.layer.borderColor = [UIColoryellowColor].CGColor;   //边框颜色  
    [self.viewaddSubview:testImageView];  
    [testImageViewrelease];  

    5.程序是启动状态时设置屏幕一直亮 
        UIApplication *appDelegate = [UIApplicationsharedApplication];
        appDelegate.idleTimerDisabled =YES;


    6.设置UITableViewCell显示子标题 
    初始化时:cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:CellIdentifier]; 
    此处样式应注意,即设置为显示子标题样式,默认样式为不显示子标题,设置完后可用: 
    cell.detailTextLabel.text =@"详细标签";    设置子标题


    7.给UIView设置阴影效果 
    [plain] view plaincopyprint? 
    UIView *showView = [[UIViewalloc]initWithFrame:CGRectMake(10,150,100,100)];   
    showView.backgroundColor = [UIColorredColor];  
    showView.layer.shadowOffset =CGSizeMake(15,5);   
    showView.layer.shadowOpacity =0.6;   
    showView.layer.shadowColor = [UIColorblackColor].CGColor;  
    [self.viewaddSubview:showView];   
    [showViewrelease];  


    8.设置UITableView选中行数的位置 
    [self.tableViewselectRowAtIndexPath:[NSIndexPathindexPathForRow:5inSection:0]animated:NOscrollPosition:UITableViewScrollPositionMiddle];  
    //selectRowAtIndexPath设置行数和section   scrollPosition设置滚动到的位置(4项可供选择)


    9.UITextField每次操作调用的代理,可根据需求作相应改变 
    - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 

        NSMutableString *newString = [[textField.textmutableCopy]autorelease]; 
        [newStringreplaceCharactersInRange:rangewithString:string];   //得到改变的字符串
    }


    10.如何用UIColor生成UIImage

    [plain] view plaincopyprint?
    - (void)viewDidLoad   
    {
        [superviewDidLoad];  
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,100,100)];  
        UIImage *image = [self createImageWithColor:[UIColoryellowColor]];   //生成一张黄颜色的图片    
        [imageViewsetImage:image];   
        [self.viewaddSubview:imageView]; 
        [imageViewrelease];  
    }    
    - (UIImage *) createImageWithColor: (UIColor *) color 
    {   
        CGRect rect = CGRectMake(0.0f,0.0f,1.0f,1.0f);   
       UIGraphicsBeginImageContext(rect.size);   
       CGContextRef context =UIGraphicsGetCurrentContext();  
       CGContextSetFillColorWithColor(context, [colorCGColor]);  
        CGContextFillRect(context, rect);   
       UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();  
       UIGraphicsEndImageContext();   
        return theImage;   
    }   
     

    原帖地址:http://www.cocoachina.com/bbs/read.php?tid=135083

  • 相关阅读:
    【机房收费系统】—— VB中 MSHFlexgrid控件导出Excel
    解决“System.Data.OracleClient 需要 Oracle 客户端软件 8.1.7 或更高版本”
    手把手教你将Python程序打包为DLL
    电脑C盘(系统盘)怎么清理,以下6个方法你学会了么?
    win7旗舰版怎么降级到专业版|win7旗舰版改成专业版的方法
    UltraISO 软碟通注册码
    “永恒之蓝”处置流程
    C#连接 ORACLE,提示System.Data.OracleClient 需要 Oracle 客户端软件 version 8.1.7 或更高版本
    RegAsm安装卸载办法
    解决Visual Studio:"无法导入以下密钥文件: xxxx.pfx,该密钥文件可能受密码保护"
  • 原文地址:https://www.cnblogs.com/yingkong1987/p/2947235.html
Copyright © 2020-2023  润新知