搜集了網(wǎng)上一些常用的開發(fā)小技巧篡悟,集中到一起看-,-
1 TableView下面的那些cell的空顯示
self.tableView.tableFooterView = [[UIView alloc] init]
2 ScrollView莫名其妙不能在viewController劃到頂怎么辦匾寝?也就是修正導航欄
self.automaticallyAdjustsScrollViewInsets = NO;
3 鍵盤事件搬葬?
使用IQKeyboardManager(GitHub上可搜索)
4 控件的局部圓角問題
你是不是也遇到過這樣的問題,一個button或者label艳悔,只要右邊的兩個角圓角急凰,或者只要一個圓角。該怎么辦呢猜年。這就需要圖層蒙版來幫助我們了
CGRect rect = CGRectMake(0, 0, 100, 50);
CGSize radio = CGSizeMake(5, 5);//圓角尺寸
UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;//這只圓角位置
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//創(chuàng)建shapelayer
masklayer.frame = button.bounds;
masklayer.path = path.CGPath;//設置路徑
button.layer.mask = masklayer;
5 navigationBar的透明問題
如果僅僅把navigationBar的alpha設為0的話抡锈,那就相當于把navigationBar給隱藏了,大家都知道乔外,父視圖的alpha設置為0的話,那么子視圖全都會透明的杨幼。那么相應的navigationBar的標題和左右兩個按鈕都會消失。這樣顯然達不到我們要求的效果补疑。
(1)如果僅僅是想要navigationBar透明歹撒,按鈕和標題都在可以使用以下方法:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];//給navigationBar設置一個空的背景圖片即可實現(xiàn)透明,而且標題按鈕都在
5 調(diào)用代碼使APP進入后臺锹杈,達到點擊Home鍵的效果迈着。
[[UIApplication sharedApplication] performSelector:@selector(suspend)];
6 獲取UIWebView的高度
- (void)webViewDidFinishLoad:(UIWebView *)webView {
CGFloat height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] intValue];
if (self.webViewHeight != height && self.count <= 3) {
self.webViewHeight = height;
self.count++;
[self updateUI];
}
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
self.webViewHeight = webView.scrollView.contentSize.height;
return YES;
}
7 帶有中文的URL處理
http://static.tripbe.com/videofiles/視頻/我的自拍視頻.mp4
NSString *path = (__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (__bridge CFStringRef)model.mp4_url, CFSTR(""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
8 禁止程序運行時自動鎖屏
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
9 用十六進制獲取UIColor
+ (UIColor *)colorWithHexString:(NSString *)color
{
NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
// String should be 6 or 8 characters
if ([cString length] < 6) {
return [UIColor clearColor];
}
// strip 0X if it appears
if ([cString hasPrefix:@"0X"])
cString = [cString substringFromIndex:2];
if ([cString hasPrefix:@"#"])
cString = [cString substringFromIndex:1];
if ([cString length] != 6)
return [UIColor clearColor];
// Separate into r, g, b substrings
NSRange range;
range.location = 0;
range.length = 2;
//r
NSString *rString = [cString substringWithRange:range];
//g
range.location = 2;
NSString *gString = [cString substringWithRange:range];
//b
range.location = 4;
NSString *bString = [cString substringWithRange:range];
// Scan values
unsigned int r, g, b;
[[NSScanner scannerWithString:rString] scanHexInt:&r];
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];
}