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輸入內(nèi)容
_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位小數(shù)
NSString*tempStr = [textField.textstringByAppendingString:string];
NSUIntegerstrlen = [tempStrlength];
if(pointRange.length>0&& pointRange.location>0){//判斷輸入框內(nèi)是否含有“.”局冰。
if([stringisEqualToString:@"."]){//當輸入框內(nèi)已經(jīng)含有“.”時,如果再輸入“.”則被視為無效。
returnNO;
}
if(strlen >0&& (strlen - pointRange.location) > remain+1){//當輸入框內(nèi)已經(jīng)含有“.”益涧,當字符串長度減去小數(shù)點前面的字符串長度大于需要要保留的小數(shù)點位數(shù)毡咏,則視當次輸入無效赃梧。
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 判斷輸入的是否是數(shù)字 保留兩位小數(shù) 用作輸入金錢判斷
AFN 圖片上傳
視頻壓縮
七牛云上傳
獲取手機內(nèi)視頻
獲取視頻第一幀
self.navigationItem.hidesBackButton=YES; // 隱藏導航左按鈕
cocoapods 相關(guān)錯誤 ,這位作者寫的很實用,推薦 http://www.reibang.com/p/dfc7b93e67eb
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied)
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"請您設(shè)置允許APP訪問您的相冊\n設(shè)置>隱私>相機" 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){
//無權(quán)限 做一個友好的提示
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"請您設(shè)置允許APP訪問您的相冊\n設(shè)置>隱私>照片" 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設(shè)置字體大小和顏色等
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
//可以通過自定義label達到自定義pickerview展示數(shù)據(jù)的方式
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];//調(diào)用上一個委托方法,獲得要展示的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];
// 將元素添加到數(shù)組指定位置
[array replaceObjectAtIndex:0 withObject:@""];
// 將替換數(shù)組指定位置元素
**8.****權(quán)限**
* 麥克風權(quán)限:Privacy - Microphone Usage Description 是否允許此App使用你的麥克風悬赏?
* 相機權(quán)限: Privacy - Camera Usage Description 是否允許此App使用你的相機狡汉?
* 相冊權(quán)限: Privacy - Photo Library Usage Description 是否允許此App訪問你的媒體資料庫?
* 通訊錄權(quán)限: Privacy - Contacts Usage Description 是否允許此App訪問你的通訊錄闽颇?
* 藍牙權(quán)限:Privacy - Bluetooth Peripheral Usage Description 是否許允此App使用藍牙盾戴?
* 語音轉(zhuǎn)文字權(quán)限:Privacy - Speech Recognition Usage Description 是否允許此App使用語音識別?
* 日歷權(quán)限:Privacy - Calendars Usage Description 是否允許此App使用日歷进萄?
* 定位權(quán)限:Privacy - Location When In Use Usage Description 我們需要通過您的地理位置信息獲取您周邊的相關(guān)數(shù)據(jù)
* 定位權(quán)限: Privacy - Location Always Usage Description 我們需要通過您的地理位置信息獲取您周邊的相關(guān)數(shù)據(jù)
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];// 創(chuàng)建系統(tǒng)級剪切板
[pasteboard setString:@"10843"];
// 調(diào)用系統(tǒng)的剪切板
uiscrollView 的分區(qū)pagingEnabled
// AppDelegate中彈出UIAlertController
UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"標題" message:@"內(nèi)容" 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設(shè)置對UICollectionView的item顯示偏移影響 ,導航欄對UICollectionView的影響 太坑了
self.tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
// 取消分區(qū)粘著效果 把尾分區(qū)高度設(shè)置為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設(shè)置不同大小的item
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
if ([_crr[section] isEqualToString:@"知名品牌"]) {
return UIEdgeInsetsMake(15, 20, 0, 20); // 內(nèi)邊距
}else{
return UIEdgeInsetsMake(0, 0, 0, 0); // 內(nèi)邊距
}
}
// 設(shè)置不同的內(nèi)邊距 相當于 flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0); // 內(nèi)邊距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(nonnull UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
if ([_crr[section] isEqualToString:@"知名品牌"]) {
return 15;// 內(nèi)邊距
}else{
return 0; // 內(nèi)邊距
}
}
相當于 flowLayout.minimumInteritemSpacing = 0;
iOS重力感應,http://www.reibang.com/p/05b8c0e3ef8c 寫的很全面,不用我在多介紹了??
cell 里獲取textField的輸入內(nèi)容
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:@","];
// 數(shù)組中元素拼接成字符串用逗號隔開
iOS隨機生成浮點數(shù)小數(shù)
int x = arc4random() % 9;
int y = (arc4random() % 10) + 10;
NSString *str=[NSString stringWithFormat:@"%d.%d",y,x];
CGFloat f =[str floatValue];
// 隨機生成兩個整數(shù) 在用小數(shù)點拼接 完美 哈哈??
[self.arr replaceObjectAtIndex:2 withObject:str];
// 修改數(shù)組中指定位置的元素
微信支付,支付失敗,提示解析失敗
package=Sign=WXPay
注意 Sign=WXPay別有空格
[[[UIApplication sharedApplication] keyWindow] addSubview:view];
// 添加視圖在最上層 不在導航和tabBar框內(nèi)
http://blog.csdn.net/qq_30600895/article/details/52329817
// 解決導航欄隱藏后切換黑閃問題
AFN解析報錯Error=3840 ---是json數(shù)據(jù)問題 如果瀏覽器可以訪問到數(shù)據(jù),在AFN中不可以的話 去除轉(zhuǎn)義字符試試
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 本地網(wǎng)絡(luò)(Local Network)權(quán)限彈框?qū)徍吮痪?/p>
cd到項目目錄檢查哪些文件使用了服務器連接
grep -r SimplePing .