ios开发技术小节

1,判断当前系统的版本

[[[UIDevice currentDevice] systemVersion ] floatValue] >= 7;这样会返回一个float的值回来,然后通过对这个值进行判断


2,播放音乐

NSString* path =[ [NSBundle mainBundle] pathForResource:@"music" ofType:@"wav"];

[NSURL *url =[ NSURL fileURLWithPath:path];

SystemSoundID soundId;

AudioSevercesCreateSystemSoundID((CFURLRef)url,&soundId);

AudioSevercesPlaySystemSound(soundId);


3.UIDevice的运用

设备相关信息获取

[[UIDevice currentDivice] name] //获取的是设备名称

[[UIDevice currentDevice] uniqueIndentifier];//获取设备唯一标示符

[[UIDevice currentDevice] systemName];//系统名称“IOS”

[[UIDevice currentDevice] systemVersion];//系统版本号 ‘4.0’

[[UIDevice currentDevice] model];//设备模式 @“iPhone” @"iPad"

[[UIDevice currentDevice] localizedModel];本地设备模式


4.关于导航栏的一些操作

//设置导航栏背景颜色
[[UINavigationBar appearance] setBarTintColor:[UIColor grayColor]];

//当然在开发过程中我们一般会使用16进制的颜色值所以只要添加一个函数就搞定啦!

 #define DEFAULT_VOID_COLOR [UIColor whiteColor]
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert
{
    NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
    
    
    if ([cString length] < 6) 
        return DEFAULT_VOID_COLOR;
    if ([cString hasPrefix:@"#"]) 
        cString = [cString substringFromIndex:1];
    if ([cString length] != 6) 
        return DEFAULT_VOID_COLOR;
    
    NSRange range;
    range.location = 0;
    range.length = 2;
    NSString *rString = [cString substringWithRange:range];
    
    range.location = 2;
    NSString *gString = [cString substringWithRange:range];
    
    range.location = 4;
    NSString *bString = [cString substringWithRange:range];
    
    
    unsigned int r, g, b;
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString] scanHexInt:&g];
    [[NSScanner scannerWithString:bString] scanHexInt:&b];
    
    return [UIColor colorWithRed:((float) r / 255.0f)
                           green:((float) g / 255.0f)
                            blue:((float) b / 255.0f)
                           alpha:1.0f];
}
/*这样是不是方便多啦!呵呵。。。*/
//当然我们还可以为导航栏添加背景图片
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg"] forBarMetrice:UIBarMetriceDefault];

//定制返回按钮

首先设置文字的颜色值
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
//
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back.png"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back.png"]];

//修改导航栏标题的字体
[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionarywithObjectsAndKeys:nil]];

//修改导航栏标题
self.navigationItem.titleView =[[UIIMageView alloc] initWithImage:[UIImage imageNamed:@"title.png"]];

//修改状态栏风格(override)
-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}
//隐藏状态栏(override)
- (BOOL)prefersStatusBarHidden
{
    return YES;
}
iOS 7 在启动期间改变状态栏颜色

防止恶意点击的操作

- (void)starButtonClicked:(id)sender

{

    //先将未到时间执行前的任务取消。

    [[self classcancelPreviousPerformRequestsWithTarget:self selector:@selector(todoSomething:object:sender];

    [self performSelector:@selector(todoSomething:withObject:sender afterDelay:0.2f];

}

时间操作

/获取当前时间
+(NSString *)getCurrentDate{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *date = [dateFormatter stringFromDate:[NSDate date]];
    return date;
}

//获取当前时间戳
+(NSString *)getCuttentStack{
    NSDate *localDate = [NSDate date];
    NSString *date = [NSString stringWithFormat:@"%ld",(long)[localDate timeInterValSince1970]];
    return date;
}

//将时间转换为时间戳
+(NSString *)changeStrTimeToStack:(NSString *)timestr
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"'yyyy'-'MM'-'dd' T 'HH':'mm':'ss'"];
    NSDate *date = [dateFormatter dataFromString:timestr];
    NSStirng *time = [NSStirng stringWithFormat:@"%ld",(long)[date timeInterValSince1970]];
    return time;
}

//将时间戳装换为时间
+(NSString *)changeTimeToStr:(NSString *)timeStack
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    NSDate *date = [NSDate dateWithTimeIntervalsince1970:[times intValue]];
    NSString *time = [dateFormatter stringFromDate:date];
    return time;
}

ARC和非ARC之间的转换操作

在开发的过程中经常会碰到有些是非ARC的文件(尤其是我们在加载第三方)的时候特别的明显,那我们要怎么搞定这个问题呢?

1.选中项目target

2,选中target中的Compile Sources

3.然后选中你需要操作的文件(是双击操作),然后会弹出一个类似编辑框的东东

4.如果你需要该文件进行ARC操作的话 输入-fobjc-arc 不需要ARC操作的 话 -fno-objc-arc就可以搞定啦!


希望对你有所帮助哈!




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值