jQuery選擇器
673
2025-03-31
判斷字符串是不是以中文開頭
- (BOOL)isChineseFirst:(NSString *)firstString { //是否以中文開頭(unicode中文編碼范圍是0x4e00~0x9fa5) int utfCode = 0; void *buffer = &utfCode; NSRange range = NSMakeRange(0, 1); //判斷是不是中文開頭的,buffer->獲取字符的字節(jié)數(shù)據(jù) maxLength->buffer的最大長度 usedLength->實際寫入的長度,不需要的話可以傳遞NULL encoding->字符編碼常數(shù),不同編碼方式轉(zhuǎn)換后的字節(jié)長是不一樣的,這里我用了UTF16 Little-Endian,maxLength為2字節(jié),如果使用Unicode,則需要4字節(jié) options->編碼轉(zhuǎn)換的選項,有兩個值,分別是NSStringEncodingConversionAllowLossy和NSStringEncodingConversionExternalRepresentation range->獲取的字符串中的字符范圍,這里設(shè)置的第一個字符 remainingRange->建議獲取的范圍,可以傳遞NULL BOOL isChinese = [firstString getBytes:buffer maxLength:2 usedLength:NULL encoding:NSUTF16LittleEndianStringEncoding options:NSStringEncodingConversionExternalRepresentation range:range remainingRange:NULL]; if (isChinese && (utfCode >= 0x4e00 && utfCode <= 0x9fa5)) return YES; else return NO; }
1
2
3
4
5
6
7
8
9
10
11
12
鍵盤回收
- (void)setUpForDismissKeyboard { UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAnywhereToDismissKeyboard:)]; NSOperationQueue *operation = [NSOperationQueue mainQueue]; [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillShowNotification object:nil queue:operation usingBlock:^(NSNotification * _Nonnull note) { [self.view addGestureRecognizer:tapGesture]; }]; [[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification object:nil queue:operation usingBlock:^(NSNotification * _Nonnull note) { [self.view removeGestureRecognizer:tapGesture]; }]; }
1
2
3
4
5
6
7
8
9
10
禁止側(cè)滑返回上一個界面
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; }
1
2
3
隱藏導(dǎo)航欄最下面的黑線
- (void)hiddenNavLine { if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){ NSArray *list=self.navigationController.navigationBar.subviews; for (id obj in list) { if ([UIDevice currentDevice].systemVersion.floatValue >= 10.0) { UIView *view = (UIView*)obj; for (id obj2 in view.subviews) { if ([obj2 isKindOfClass:[UIImageView class]]) { UIImageView *image = (UIImageView*)obj2; image.hidden = YES; } } } } } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
去除自帶的searchBar的背景View
- (void)removeSearchBarBackGroundView { for(int i = 0 ;i < _searchBar.subviews.count;i++){ UIView * backView = _searchBar.subviews[i]; if ([backView isKindOfClass:NSClassFromString(@"UISearchBarBackground")] == YES) { [backView removeFromSuperview]; [_searchBar setBackgroundColor:[UIColor clearColor]]; break; } else { NSArray * arr = _searchBar.subviews[i].subviews; for(int j = 0;j < arr.count; j++){ UIView * barView = arr[i]; if ([barView isKindOfClass:NSClassFromString(@"UISearchBarBackground")] == YES) { [barView removeFromSuperview]; [_searchBar setBackgroundColor:[UIColor clearColor]]; break; } } } } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
標(biāo)簽欄的背景圖顯示錯亂問題解決辦法:
//將圖片如下設(shè)置 [[UIImage imageNamed:@"me@2x.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
1
2
網(wǎng)絡(luò)請求設(shè)置超時請求(基于AFNetworking3.0封裝的GET,POST請求用方法)
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; [manager.requestSerializer willChangeValueForKey:@"timeoutInterval"]; manager.requestSerializer.timeoutInterval = 15.f; [manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
1
2
3
4
實用的獲取圖片的方法,防止內(nèi)存溢出:
// 建議使用該方法: NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"圖片" ofType:@"png"]; UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath]; // 不建議使用該方法: UIImage *image = [UIImage imageNamed:@"圖片.png"];
1
2
3
4
5
6
iOS
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實的內(nèi)容,請聯(lián)系我們jiasou666@gmail.com 處理,核實后本網(wǎng)站將在24小時內(nèi)刪除侵權(quán)內(nèi)容。