IOS开发常用代码汇总3

来源:互联网 发布:淘宝网店如何引流量 编辑:程序博客网 时间:2024/06/05 12:40

21.获取当前版本

    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

22.控件的动画效果


    [UIViewbeginAnimations:nilcontext:nil];

[UIViewsetAnimationDuration:0.3];

    if (isOn) {

        isOn=NO;


        self.titleLab.hidden=YES;

        self.ipLab.hidden=YES;

        self.switcher.frame =CGRectMake(150, 339, 50, 32);

    }else

    {

        isOn=YES;


        self.titleLab.hidden=NO;

        self.ipLab.hidden=NO;

        self.switcher.frame =CGRectMake(105, 339, 50, 32);


        

    }

    [UIViewcommitAnimations];

    

23.给一个UIImageView对象 添加单击事件

    self.imageView.userInteractionEnabled=YES;

    UITapGestureRecognizer *single=[[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(onClickSwitcher:)];

    [self.imageViewaddGestureRecognizer:single];

    [single release];


    

24.获取当前系统时间,返回string类型

+ (NSString*)GetNowTimeEX

{

NSDateFormatter *formate = [[NSDateFormatteralloc] init];

[formate setDateFormat:@"yyyyMMddHHmmssSSS"];

NSString *nowString = [formatestringFromDate:[NSDate date]];

[formate release];

return nowString;

}


25.转换时间格式,返回string类型

+ (NSString*)GetTimeStringByString:(NSString*)timeStr

{

NSDateFormatter *formate = [[NSDateFormatteralloc] init];

[formate setDateFormat:@"yyyyMMddHHmmss"];

NSDate *ndate = [formate dateFromString:timeStr];

[formate setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

NSString* timeSting = [formatestringFromDate:ndate];

[formate release];

return timeSting;

}

26.判断文件是否存在

+ (BOOL)isExsiteFile:(NSString*)filePath

{

if (!filePath) {

returnNO;

}

NSFileManager *fileMage = [NSFileManagerdefaultManager];

return [fileMage fileExistsAtPath:filePath];

}

27. 键盘上的return键改成Done:

    textField.returnKeyType =UIReturnKeyDone;

28.textfield设置成为密码框

       [textField_pwd setSecureTextEntry:YES];

29.隐藏状态栏

   [UIApplication  sharedApplication]setStatusBarHidden:YES animated:NO];

30. 防止屏幕暗掉锁屏

    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];

原创粉丝点击