1 點擊背景時關閉鍵盤
在viewDidLoad中添加手勢辨識器
// add tap gesture recognizer UITapGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleBackgroundTap:)]; tapRecognizer.cancelsTouchesInView = NO; [self.view addGestureRecognizer:tapRecognizer];
定義函數
- (void) handleBackgroundTap:(UITapGestureRecognizer*)sender{ [phoneField resignFirstResponder]; [nameField resignFirstResponder]; [postcodeField resignFirstResponder]; }
在該函數使文字欄位取消第一響應者狀態.
2 圖片作為填充顏色
[UIColor colorWithPatternImage: [UIImage imageNamed:@"background"];
3 建立和繪製漸層
View Code
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); UIColor *startColor = [UIColor blueColor]; CGFloat *startColorComponents = (CGFloat *)CGColorGetComponents([startColor CGColor]); UIColor *endColor = [UIColor greenColor]; CGFloat *endColorComponents = (CGFloat *)CGColorGetComponents([endColor CGColor]); CGFloat colorComponents[8] = { startColorComponents[0], startColorComponents[1], startColorComponents[2], startColorComponents[3], endColorComponents[0], endColorComponents[1], endColorComponents[2], endColorComponents[3], }; CGFloat colorIndices[2] = { 0.0f, 1.0f, }; CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, (const CGFloat *)&colorComponents, (const CGFloat *)&colorIndices, 2); CGColorSpaceRelease(colorSpace); CGRect screenBounds = [[UIScreen mainScreen] bounds]; CGPoint startPoint, endPoint; CGContextRef context = UIGraphicsGetCurrentContext(); startPoint = CGPointMake(0.0f,screenBounds.size.height/2.0f); endPoint = CGPointMake(screenBounds.size.width, startPoint.y); CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0); CGGradientRelease(gradient);
4 載入顯示網頁
View Code
NSURL *url = [NSURL URLWithString:_detailItem]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [_webView loadRequest:request];
5 導航條載入圖片做背景
6 UIView加陰影
View Code
sepLine = [[UIView alloc] init ]; sepLine.frame = CGRectMake(LEFT_MARGIN+5, 0, cellWidth-LEFT_MARGIN-RIGHT_MARGIN, 1); //加陰影 CAGradientLayer *bottomShadow = [[CAGradientLayer alloc] init]; bottomShadow.frame = CGRectMake(2, 0, cellWidth-LEFT_MARGIN-RIGHT_MARGIN+2, 1); CGColorRef black = [UIColor lightGrayColor].CGColor; CGColorRef white = [UIColor whiteColor].CGColor; bottomShadow.colors = [NSArray arrayWithObjects:(__bridge id)black,(__bridge id)white, nil]; [sepLine.layer addSublayer:bottomShadow];
7 iOS 同步 synchronization
使用NSLock和@synchronized來保護臨界區
還可以用dispatch_sync
8 擷取螢幕資訊
UIScreen用於擷取當前所有螢幕(包括裝置主畫面)的螢幕對象。螢幕對象包含螢幕的屬性資訊(包括將螢幕的尺寸和
像素比例也考慮在內的螢幕特徵)。
9 資產庫架構
iOS 4.0引入了資產庫架構(AssetsLibrary.framework),該架構提供一個查詢介面,您可以通過它尋找使用者照片和資料。通過使用該架構,您可以訪問Photos管理的資產,包括使用者儲存的相簿以及匯入到裝置中的圖片或視頻。而且您也可以將照片或者視頻儲存到使用者的相簿。