《iOS遊戲編程之從零開始-Cocos2dx與cocos2d引擎開發》這本數確實很適合初學者使用。裡邊的知識由簡入深,給零基礎iOS開發人員做了細緻而深入的講解。我將iOS開發中的一些小知識和大家分享分享吧。
1、壓縮圖片:UIImage *yourImage= [self imageWithImageSimple:image scaledToSize:CGSizeMake(210.0,
210.0)];
- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize { // Create a graphics image context UIGraphicsBeginImageContext(newSize); // Tell the old image to draw in this newcontext, with the desired // new size [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; // Get the new image from the context UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); // End the context UIGraphicsEndImageContext(); // Return the new image. return newImage; }
2、URL編碼
NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes (NULL, (CFStringRef)yourtext, NULL, (CFStringRef)@”!*’();:@&=+$,/?%#[]“, kCFStringEncodingUTF8);
3、設定navigationBar隱藏
self.navigationController.navigationBarHidden = YES;
4、imageView載入圖片
UIImage *myImage = [UIImage imageNamed:@"1.jpg"]; [imageView setImage:myImage]; [self.view addSubview:imageView];
5、停止UIView動畫的方法
#import<QuartzCore/QuartzCore.h>[self.view.layer removeAllAnimations];
6、通過tag取cell上的控制項
[cell.contentView viewWithTag:tag];