IOS开发常用代码汇总3

21.获取当前版本

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

22.控件的动画效果


    [UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration: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);


        

    }

    [UIView commitAnimations];

    

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

    self.imageView.userInteractionEnabled=YES;

    UITapGestureRecognizer *single=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickSwitcher:)];

    [self.imageView addGestureRecognizer:single];

    [single release];


    

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

+ (NSString*)GetNowTimeEX

{

NSDateFormatter *formate = [[NSDateFormatter alloc] init];

[formate setDateFormat:@"yyyyMMddHHmmssSSS"];

NSString *nowString = [formate stringFromDate:[NSDate date]];

[formate release];

return nowString;

}


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

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

{

NSDateFormatter *formate = [[NSDateFormatter alloc] init];

[formate setDateFormat:@"yyyyMMddHHmmss"];

NSDate *ndate = [formate dateFromString:timeStr];

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

NSString* timeSting = [formate stringFromDate:ndate];

[formate release];

return timeSting;

}

26.判断文件是否存在

+ (BOOL)isExsiteFile:(NSString*)filePath

{

if (!filePath) {

return NO;

}

NSFileManager *fileMage = [NSFileManager defaultManager];

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值