IOS项目中的细节处理,如更改状态栏等等
一,状态栏更改为白色
1 在info.plist中添加一个字段:view controller -base status bar 为NO

2 在需要改变状态栏颜色的ViewController中在ViewDidLoad方法中增加:
[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
如果需要在全部View中都变色,可以写在父类的相关方法中,或者写到AppDelegate中。
二 :去除navigationbar 底部黑线 ——亲测可用
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
NSArray *list=self.navigationController.navigationBar.subviews;
for (id obj in list) {
if ([obj isKindOfClass:[UIImageView class]]) {
UIImageView *imageView=(UIImageView *)obj;
NSArray *list2=imageView.subviews;
for (id obj2 in list2) {
if ([obj2 isKindOfClass:[UIImageView class]]) {
UIImageView *imageView2=(UIImageView *)obj2;
imageView2.hidden=YES;
}
}
}
}
}
1、采用imageNamed方法的图片加载情况
图片资源反复使用到,如按钮背景图片的蓝色背景,这些图片要经常用到,而且占用内存少
2、不应该采用的情况:
(1)图片一般只使用一次,如一些用户的照片资源
(2)图片资源较大,加载到内存后,比较耗费内存资源
四 Unix时间转换
NSNumber *dateStr = [data valueForKey:@"lastLogTime"]; double unixTimeStamp = [dateStr doubleValue]; NSTimeInterval _interval=unixTimeStamp; NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval]; NSDateFormatter *_formatter=[[NSDateFormatter alloc]init]; [_formatter setLocale:[NSLocale currentLocale]]; [_formatter setDateFormat:@"dd.MM.yyyy"]; NSString *_date=[_formatter stringFromDate:date];
或者:
[obj printAllPropertys];
nameLabel.text = [obj valueForKey:@"empName"];
orgLabel.text = [obj valueForKey:@"orgName"];
positionLabel.text = [obj valueForKey:@"position"];
cellPhoneLabel.text = [obj valueForKey:@"cellphone"];
NSString *dateNumber = [obj valueForKey:@"lastLogTime"];
NSLog(@"dateNumber%@",dateNumber);
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy/mm/dd hh:mm:ss"];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Beijing"];
[dateFormatter setTimeZone:timeZone];
//[dateFormatter setLocale:[NSLocale currentLocale]];
double unixTimeStamp = [dateNumber doubleValue];
NSTimeInterval _interval=unixTimeStamp;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:_interval];
timeStr=[dateFormatter stringFromDate:date];
NSLog(@"loginTime:%@,_interval:%@",timeStr,dateNumber);
五,ios获取app版本号和项目名称
NSString *executableFile = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleExecutableKey]; //获取项目名称
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]; //获取项目版本号
浅谈IOS版本号:http://segmentfault.com/a/1190000002423661
NSString *deviceID = (NSString*) [[UIDevice currentDevice] identifierForVendor];//设备id
// NSString *deviceID = [UIApplication sharedApplication] uuid];
NSString *systemVersion = [[UIDevice currentDevice] systemVersion];//系统版本
NSString *systemModel = [[UIDevice currentDevice] model];//是iphone 还是 ipad
NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];//获取info-plist
NSString *appName = [dic objectForKey:@"CFBundleIdentifier"];//获取Bundle identifier
NSString *appVersion = [dic valueForKey:@"CFBundleVersion"];//获取Bundle Version
NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:
deviceID, @"deviceID",
systemVersion, @"systemVersion",
systemModel, @"systemModel",
appName, @"appName",
appVersion, @"appVersion",nil];
NSLog(@"dic:%@",userInfo);
六,修改SearchBar的取消按钮的字体
///#begin
//
//功能描述:修改SearchBar的Cancel Button 的Title
// 注意点:
// 使用iOS8 SDK ,本次 UISearchBar适用于iOS7(+)版本,如果想要适配iOS6,则需要对应适配iOS6.
// 例如:
// iOS7+ : for(id cc in [searchBar.subviews[0] subviews]){}
// iOS7- : for(id cc in [searchBar subviews]){}
//
///#end
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
for(id cc in [searchBar.subviews[0] subviews])
{
if([cc isKindOfClass:[UIButton class]])
{
UIButton *btn = (UIButton *)cc;
[btn setTitle:[AppLanguageProcess getLanguageWithKey:@"TEXT_CANCEL"] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
}
}
待续