self.navigationController.navigationBar.translucent=NO; // 导航栏半透明属性
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"daohang.jpg"]forBarMetrics:UIBarMetricsDefault]; // 导航栏上放背景图片
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(textFieldDidChange)name:@"UITextFieldTextDidChangeNotification"object:nil];
- (void)textFieldDidChange{
self.searchStr=self.searchTFd.text;
} // 实时获取textField输入内容
_Introduction_Lab= [[UILabelalloc]initWithFrame:CGRectMake(0,5,WIDTHOFMAIN/1.25,HEIGHTOFMAIN/10)];
_Introduction_Lab.enabled=NO;
_Introduction_Lab.font=[UIFontsystemFontOfSize:14];
_Introduction_Lab.text=@"限300字";
_Introduction_Lab.numberOfLines=0;
_Introduction_Lab.textColor= [UIColorlightGrayColor];
[self.contentTFdaddSubview:_Introduction_Lab];
- (void)textViewDidChange:(UITextView*)textView
{
if([textView.textlength] ==0) {
[_Introduction_LabsetHidden:NO];
}else{
[_Introduction_LabsetHidden:YES];
} } } // textView上加水印字
- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string
{
NSScanner*scanner= [NSScannerscannerWithString:string];
NSCharacterSet*numbers;
NSRangepointRange = [textField.textrangeOfString:@"."];
if( (pointRange.length>0) && (pointRange.location< range.location|| pointRange.location> range.location+ range.length) )
{
numbers = [NSCharacterSetcharacterSetWithCharactersInString:@"0123456789"];
}
else
{
numbers = [NSCharacterSetcharacterSetWithCharactersInString:@"0123456789."];
}
if( [textField.textisEqualToString:@""] && [stringisEqualToString:@"."] )
{
returnNO;
}
shortremain =2;//默认保留2位小数
NSString*tempStr = [textField.textstringByAppendingString:string];
NSUIntegerstrlen = [tempStrlength];
if(pointRange.length>0&& pointRange.location>0){//判断输入框内是否含有“.”。
if([stringisEqualToString:@"."]){//当输入框内已经含有“.”时,如果再输入“.”则被视为无效。
returnNO;
}
if(strlen >0&& (strlen - pointRange.location) > remain+1){//当输入框内已经含有“.”,当字符串长度减去小数点前面的字符串长度大于需要要保留的小数点位数,则视当次输入无效。
returnNO;
}
}
NSRangezeroRange = [textField.textrangeOfString:@"0"];
if(zeroRange.length==1&& zeroRange.location==0){//判断输入框第一个字符是否为“0”
if(![stringisEqualToString:@"0"] && ![stringisEqualToString:@"."] && [textField.textlength] ==1){//当输入框只有一个字符并且字符为“0”时,再输入不为“0”或者“.”的字符时,则将此输入替换输入框的这唯一字符。
textField.text= string;
returnNO;
}else{
if(pointRange.length==0&& pointRange.location>0){//当输入框第一个字符为“0”时,并且没有“.”字符时,如果当此输入的字符为“0”,则视当此输入无效。
if([stringisEqualToString:@"0"]){
returnNO;
}
}
}
}
NSString*buffer;
if( ![scannerscanCharactersFromSet:numbersintoString:&buffer] && ([stringlength] !=0) )
{
returnNO;
}
returnYES;
} // textField 判断输入的是否是数字 保留两位小数 用作输入金钱判断
AFN 图片上传
视频压缩
七牛云上传
获取手机内视频
获取视频第一帧
self.navigationItem.hidesBackButton=YES; // 隐藏导航左按钮
cocoapods 相关错误 ,这位作者写的很实用,推荐 //www.greatytc.com/p/dfc7b93e67eb
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied)
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"请您设置允许APP访问您的相册\n设置>隐私>相机" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alertController animated:YES completion:nil];
UIAlertAction *defauleAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:defauleAction];
// 访问相机被拒绝
ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];;
if (author == ALAuthorizationStatusRestricted || author ==ALAuthorizationStatusDenied){
//无权限 做一个友好的提示
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"请您设置允许APP访问您的相册\n设置>隐私>照片" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alertController animated:YES completion:nil];
UIAlertAction *defauleAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self.navigationController popViewControllerAnimated:YES];
}];
[alertController addAction:defauleAction];
return ;
} else {
//打开相册
}
// 访问相册被拒绝
#pragma mark 给pickerview设置字体大小和颜色等
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
//可以通过自定义label达到自定义pickerview展示数据的方式
UILabel* pickerLabel = (UILabel*)view;
if (!pickerLabel){
pickerLabel = [[UILabel alloc] init];
pickerLabel.adjustsFontSizeToFitWidth = YES;
pickerLabel.textAlignment = NSTextAlignmentCenter;
[pickerLabel setFont:[UIFont boldSystemFontOfSize:25]];
}
pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];//调用上一个委托方法,获得要展示的title
return pickerLabel;
}
label_one.font = [UIFont boldSystemFontOfSize:14];
lable字体加粗
模拟器运行报错[The request to open "your bundle id" failed]
报错详情The request was denied by service delegate (SBMainWorkspace) for reason:....等等解决方法
将那个对号点没 就可以了
// textField弹键盘,然后回上一界面,键盘回收延迟问题
- (void)viewWillDisappear:(BOOL)animated
{
[self.view endEditing:YES];
[self.searchTFd resignFirstResponder];
[super viewWillDisappear:YES];
}
// 如果是searchBar的话
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[self.view endEditing:YES];
_m_key = searchBar.text;
[self setupRefreshView];
}
[array insertObject:@"" atIndex:0];
// 将元素添加到数组指定位置
[array replaceObjectAtIndex:0 withObject:@""];
// 将替换数组指定位置元素
**8.****权限**
* 麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风?
* 相机权限: Privacy - Camera Usage Description 是否允许此App使用你的相机?
* 相册权限: Privacy - Photo Library Usage Description 是否允许此App访问你的媒体资料库?
* 通讯录权限: Privacy - Contacts Usage Description 是否允许此App访问你的通讯录?
* 蓝牙权限:Privacy - Bluetooth Peripheral Usage Description 是否许允此App使用蓝牙?
* 语音转文字权限:Privacy - Speech Recognition Usage Description 是否允许此App使用语音识别?
* 日历权限:Privacy - Calendars Usage Description 是否允许此App使用日历?
* 定位权限:Privacy - Location When In Use Usage Description 我们需要通过您的地理位置信息获取您周边的相关数据
* 定位权限: Privacy - Location Always Usage Description 我们需要通过您的地理位置信息获取您周边的相关数据
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];// 创建系统级剪切板
[pasteboard setString:@"10843"];
// 调用系统的剪切板
uiscrollView 的分区pagingEnabled
// AppDelegate中弹出UIAlertController
UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"标题" message:@"内容" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *sureAction=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { }]; [alertController addAction:sureAction];
UIWindow *alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; alertWindow.rootViewController = [[UIViewController alloc] init]; alertWindow.windowLevel = UIWindowLevelAlert + 1; [alertWindow makeKeyAndVisible]; [alertWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
self.automaticallyAdjustsScrollViewInsets = NO;
// NavigationBar设置对UICollectionView的item显示偏移影响 ,导航栏对UICollectionView的影响 太坑了
self.tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
// 取消分区粘着效果 把尾分区高度设置为1 搞定
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return CGSizeMake(WIDTHOFMAIN / 2, HEIGHTOFMAIN / 3);
}else{
return CGSizeMake(WIDTHOFMAIN / 3, HEIGHTOFMAIN / 3.5);
}
}
// collectionView设置不同大小的item
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
if ([_crr[section] isEqualToString:@"知名品牌"]) {
return UIEdgeInsetsMake(15, 20, 0, 20); // 内边距
}else{
return UIEdgeInsetsMake(0, 0, 0, 0); // 内边距
}
}
// 设置不同的内边距 相当于 flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); // 内边距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(nonnull UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
if ([_crr[section] isEqualToString:@"知名品牌"]) {
return 15;// 内边距
}else{
return 0; // 内边距
}
}
相当于 flowLayout.minimumInteritemSpacing = 0;
iOS重力感应,//www.greatytc.com/p/05b8c0e3ef8c 写的很全面,不用我在多介绍了😑
cell 里获取textField的输入内容
cellForRowAtIndexPath中
cell.textField.tag = indexPath.row;
[cell.textField addTarget:self action:@selector(textFieldWithText:) forControlEvents:UIControlEventEditingChanged];
-(void)textFieldWithText:(UITextField *)textfield
{
NSLog(@"%@",textfield.text);
}
self.str = [arr componentsJoinedByString:@","];
// 数组中元素拼接成字符串用逗号隔开
iOS随机生成浮点数小数
int x = arc4random() % 9;
int y = (arc4random() % 10) + 10;
NSString *str=[NSString stringWithFormat:@"%d.%d",y,x];
CGFloat f =[str floatValue];
// 随机生成两个整数 在用小数点拼接 完美 哈哈😝
[self.arr replaceObjectAtIndex:2 withObject:str];
// 修改数组中指定位置的元素
微信支付,支付失败,提示解析失败
package=Sign=WXPay
注意 Sign=WXPay别有空格
[[[UIApplication sharedApplication] keyWindow] addSubview:view];
// 添加视图在最上层 不在导航和tabBar框内
http://blog.csdn.net/qq_30600895/article/details/52329817
// 解决导航栏隐藏后切换黑闪问题
AFN解析报错Error=3840 ---是json数据问题 如果浏览器可以访问到数据,在AFN中不可以的话 去除转义字符试试
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer.acceptableContentTypes= [NSSet setWithObject:@"text/html"];
[manager POST:_URL parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
NSString * str = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];
NSString * str2 = [str stringByReplacingOccurrencesOfString:@"\t" withString:@""];
str2 = [str2 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
str2 = [str2 stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[str dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:nil];
NSLog(@"d11ic3t =%@",dict);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
NSLog(@"er1112ror =%@",error);
}];
URLEncodedString 编码
CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)@"str",
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8));
URLDecodedString 解码
(__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (__bridge CFStringRef)@"str", CFSTR(""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding))
Xcode 格式化代码 control + i;
git clone --depth=1 https://code.aliyun.com/Magi/CocoaPods.git ~/.cocoapods/repos/master
cocoapods新的get源
iOS14 本地网络(Local Network)权限弹框审核被拒
cd到项目目录检查哪些文件使用了服务器连接
grep -r SimplePing .