1.使用系统tabbar时,tabbar上方会有一条线,如果想去掉这条线,添加如下代码即可:
[self.tabBar setClipsToBounds:YES];
2.调用系统相机拍照或者录像完成后,返回后出现导航栏上移的问题,效果图如下:
解决办法,检查info.plist文件中是否设置View controller-based status bar appearance
字段,如果设置,将其改为NO即可,更多关于View controller-based status bar appearance
的相关知识参考链接View controller-based status bar appearance
3.知道时区,计算不同国家的当前时间的方法如下:
//timer为时区
NSInteger timer = [time_zone integerValue];
NSDate *currentDate = [NSDate date];
NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"MM/d HH:mm"];
if (timer > 0) {
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:(8 + timer * 3600)]];
}else{
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:(8 + (timer - 1) * 3600)]];
}
NSString *dateStr = [formatter stringFromDate:currentDate];`
4.当tableView的样式选择为plain样式时,分区头就处于悬浮状态,如果不想要这种悬浮状态,则需要将tableView的样式修改为grouped样式,但是修改成grouped样式之后,会发现分区头上面会有一个留白,想要去除留白,则需要实现下面的代理方法,注意不要将高度返回为0,否则将没有效果
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.01;
}
5.设置tabbar背景颜色的方法
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SelfWideh, 49)];
backView.backgroundColor = [UIColor whiteColor];
[self.tabBar insertSubview:backView atIndex:0];
self.tabBar.opaque = YES;
6.选取系统照片,如果想使用原图,可以进行如下设置
//选取照片时设置
imagePicker.allowsEditing = NO;//不允许编辑
读取照片时,读取原图
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
7.iOS实现多级界面模态之后的返回
UIViewController *rootVC = self.presentingViewController;
while (rootVC.presentingViewController) {
rootVC = rootVC.presentingViewController;
}
[rootVC dismissViewControllerAnimated:YES completion:nil];
8.限制TextField输入的内容的长度的方法
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
{ //string就是此时输入的那个字符textField就是此时正在输入的那个输入框返回YES就是可以改变输入框的值NO相反
if ([string isEqualToString:@"\n"]) //按会车可以改变
{
return YES;
}
NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string]; //得到输入框的内容
VerifyCodeCell *cell = [self.view viewWithTag:3000];
if (cell.pwdTF == textField) //判断是否时我们想要限定的那个输入框
{
if ([toBeString length] > 16) { //如果输入框内容大于20则弹出警告
textField.text = [toBeString substringToIndex:16];
return NO;
}
}
return YES;
}
9.解决多次present之后返回到指定的界面
UIViewController *vc =self.presentingViewController;
//BondDeviceController要跳转的界面
while (![vc isKindOfClass:[BondDeviceController class]]) {
vc = vc.presentingViewController;
}
[vc dismissViewControllerAnimated:YES completion:nil];
10.控制输入框中输入的内容都为大写字母的方法
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSRange lowercaseCharRange;
lowercaseCharRange = [string rangeOfCharacterFromSet:[NSCharacterSet lowercaseLetterCharacterSet]];
if (lowercaseCharRange.location != NSNotFound) {
textField.text = [textField.text stringByReplacingCharactersInRange:range
withString:[string uppercaseString]];
return NO;
}
return YES;
}
11.如何修改UITabbarItem上面图片的位置和文字的位置
PersonalViewController *VC3 = [[PersonalViewController alloc]init];
VC3.tabBarItem.title = @"个人";
VC3.tabBarItem.image = [UIImage imageNamed:@"个人灰色"];
VC3.tabBarItem.selectedImage = [[UIImage imageNamed:@"个人亮色"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//设置文字的位置
[VC3.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -5)];
//设置图片的位置
VC3.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
12.label自适应高度的代码
SystemInfoCell *cell = [self.view viewWithTag:3000];
//这里文字的大小一定要和控件的文字大小保持一致
NSDictionary *attrs = @{NSFontAttributeName : [UIFont fontWithName:@"HiraginoSansGB-W3" size:[self autoScaleW:14]]};
CGSize maxSize = CGSizeMake(cell.contentLabel.frame.size.width, MAXFLOAT);
// 计算文字占据的高度
CGRect rect = [cell.contentLabel.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil];
网友评论