iOS的一些小技巧
状态栏文字颜色修改
//info.plist中添加一个字段:view controller -base status bar 设置为NO 设置状态栏文字为白色 //有动画效果 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES]; //无动画效果 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
状态栏自定义~
UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]; statusBarView.backgroundColor=[UIColor blackColor]; [YouNav.view addSubview:statusBarView]; [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
Tabbar透明
UITabBarController *tabVC = [[UITabBarController alloc] init]; //获得tabbar UITabBar *tabBar = tabVC.tabBar; //设置透明度 [tabBar setAlpha:0.8f];
TabBar badgeValue
//tabbar index int TabIndex = 1; //bageValue NSString *badgeValue = [NSString stringWithFormat:@"%d",num++]; //Set [[[[[self tabBarController] viewControllers] objectAtIndex: TabIndex] tabBarItem] setBadgeValue:badgeValue];
TabBar字体,大小,颜色
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:0.439f green:0.435f blue:0.439f alpha:1.00f], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:11], NSFontAttributeName,nil] forState:UIControlStateNormal]; //选中后颜色 [tabBar setTintColor:[UIColor colorWithRed:0.212f green:0.682f blue:0.776f alpha:1.00f]];
GitHub
//终端本地生成Key,路径 /User/YourMacName/.ssh/ 用文本编辑器打开后,复制到github的addsshkey的页面中 $ ssh-keygen -t rsa -C "your_email@youremail.com"
//Github Push等不正常. 改协议, HTTPS->SSH //只要将地址按如下格式即可... https://github.com/USERNAME/OTHERREPOSITORY.git git@github.com:USERNAME/OTHERREPOSITORY.git
放置多个UITableView或UICollectionView,首个UITableView,UICollectionView布局不正确
原因是iOS默认开启了自动布局,而第一个添加的view,会被默认拉伸适配.
//解决方法一,在self.view 的第一层添加一空白view [self.view addSubview:[UIView new]]; //解决方法二 关闭自动布局 self.automaticallyAdjustsScrollViewInsets = NO;
AFNetWorking传输json数组,对数组进行jason序列化
+ (void)PostData:(NSString*)url NotificationName:(NSString*)Name ForKey:(NSString*)Key SetArrayParameters:(NSArray*)parameters { AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
// 设置发送请求格式 manager.requestSerializer = [AFJSONRequestSerializer serializer]; // 设置返回格式 //manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:[NSString stringWithFormat:@"%s%@",ServerUrl,url] parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { if (responseObject) { [[NSNotificationCenter defaultCenter]postNotificationName:Name object:self userInfo:[NSDictionary dictionaryWithObject:responseObject forKey:Key]]; NSLog(@"res:%@",responseObject); } } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; }
使用KVO的时候千万要记得取消通知注册,否则会出现重复收到数据的情况.尤其是
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(UpdateStatus:) name:@"getBlance" object:nil];
写在viewload,viewWillAppear等,会造成通知重复注册多次.如果在UpdateStatus还写有响应的网络请求,就会出现多次重复提交的情况
-(void)viewWillDisappear:(BOOL)animated { [[NSNotificationCenter defaultCenter] removeObserver:self name:@"getBlance" object:nil]; [[NSNotificationCenter defaultCenter] removeObserver:self name:@"AddPassVerify" object:nil]; }
多变的自定义Cell,解决重用机制会导致内容出错 UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:defineString] 修改为:UITableViewCell *cell = [tableview cellForRowAtIndexPath:indexPath];
自定义字体有时候会碰到在模拟器上可用,在真机上获取不到的情况.一般是模拟器上的字体名和真机上的不一样(这点我不确定).总之还是直接跑下面的代码,获取字体名,比较好.
NSArray *familyNames =[[NSArray alloc]initWithArray:[UIFont familyNames]]; NSArray *fontNames; NSInteger indFamily, indFont; NSLog(@"[familyNames count]===%lu",(unsigned long)[familyNames count]); for(indFamily=0;indFamily<[familyNames count];++indFamily) { NSLog(@"Family name:%@", [familyNames objectAtIndex:indFamily]); fontNames =[[NSArray alloc]initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]]; for(indFont=0; indFont<[fontNames count]; ++indFont) { NSLog(@"Font name:<%@>",[fontNames objectAtIndex:indFont]); } }
待续。。。