应用键横竖屏切换;label中显示图片;不同类型装置适配的代码;UIWebView字体大小、字体颜色、背景色的设置
最近总结的工作中遇到的小问题在这里共享 ,希望对大家能有帮助
1.横屏的一个应用在修改个人资料过程从相册取图片或者拍照的过程中,横纵屏切换引起再次进入程序时应用变纵屏的bug
[actionSheet showInView:self.view];
}
-(void) actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if ( buttonIndex ==0) {
NSLog(@"相机");
}elseif( buttonIndex ==1){
}else{
NSLog(@"取消了啊啊");
}
[selfsaveValue:@"hengping"WithKey:@"hengping"];}
-(void) saveValue:(NSObject*) value WithKey:(NSString*) key {
NSUserDefaults * def = [NSUserDefaultsstandardUserDefaults];
[def setObject:valueforKey:key];
[def synchronize];
}
//从相机中选
-(void)selectCamera{
if ([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *image = [[UIImagePickerControlleralloc]init];
image.delegate= self;
image.allowsEditing= YES;
image.sourceType= UIImagePickerControllerSourceTypeCamera;
[selfdismissViewControllerAnimated:YEScompletion:nil];
[selfpresentViewController:imageanimated:YEScompletion:^{}];
}else{
NSLog(@"请确定相机是否能正常打开");
}
}
//从相册中选择
-(void)selectPhotos{
if ([DkUIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;//保存的相片
DkUIImagePickerController *picker = [[DkUIImagePickerControlleralloc]init];
picker.delegate= self;
picker.allowsEditing= YES;//是否允许编辑
picker.sourceType= sourceType;
[selfdismissViewControllerAnimated:YEScompletion:^{
}];
[selfpresentViewController:pickeranimated:YEScompletion:nil];
}else{
}
}
-(void) pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSLog(@"选择了照片");
}
-(void) imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{
UIImage *img = info[UIImagePickerControllerEditedImage];
UIImage *newImage = [selfimageCompressForWidth:imgtargetWidth:ScreenWidth];
self.informationView.PersonIconimage= newImage;
[self.informationViewrefresh];
[picker dismissViewControllerAnimated:YEScompletion:nil];
self.informationView.PickBgView.hidden= YES;
}
-(void) imagePickerControllerDidCancel:(UIImagePickerController*)picker{
[picker dismissViewControllerAnimated:YEScompletion:^{
}];
NSLog(@"取消");
[self.viewendEditing:YES];
NSUserDefaults * def = [NSUserDefaultsstandardUserDefaults];
[def removeObjectForKey:@"hengping"];
@end
@implementationDkUIImagePickerController
///指定UIImagePickerController只支持横屏方向
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
//设置状态栏的状态
-(UIStatusBarStyle) preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
-(BOOL) shouldAutorotate{
return YES;
}
-(NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
NSString* strSubClass = [NSStringstringWithUTF8String:object_getClassName(window.rootViewController.presentedViewController)];
if ([@"ImgTakeViewController"isEqualToString:strSubClass]) {
return UIInterfaceOrientationMaskAll;
}
return [applicationsupportedInterfaceOrientationsForWindow:window];
}
-(BOOL) prefersStatusBarHidden{
return YES;
}
}
NSUserDefaults * def = [NSUserDefaultsstandardUserDefaults];
return [def objectForKey:key];
- (void)webViewDidFinishLoad:(UIWebView*)webView{
//字体大小
[webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '70%'"];
//字体颜色
[webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'white'"];
//页面背景色
[webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#2E2E2E'"];
self.myWebView.opaque = NO;//不设置这个值 页面背景始终是白色
self.myWebView.backgroundColor = [UIColor clearColor];
self.myWebView.scalesPageToFit = NO; //禁止用户缩放页面
self.myWebView.dataDetectorTypes = UIDataDetectorTypePhoneNumber|UIDataDetectorTypeLink;
self.myWebView.scrollView.pagingEnabled = YES;
self.myWebView.scrollView.contentInset = UIEdgeInsetsMake(0, 0,0, 0);
self.myWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.myWebView];
[myObject isKindOfClass:[NSString class]]
[myObject isKindOfClass:[UIImageView class]]
BOOL test = [self isKindOfClass:[SomeClass class]];
for(id element in myArray)
{
NSLog(@"=======================================");
NSLog(@"Is of type: %@", [element className]);
NSLog(@"Is of type NSString?: %@", ([[element className] isMemberOfClass:[NSString class]])? @"Yes" : @"No");
NSLog(@"Is a kind of NSString: %@", ([[element classForCoder] isSubclassOfClass:[NSString class]])? @"Yes" : @"No");
}
[UIDevice currentDevice] uniqueIdentifier]
uniqueIdentifier在UIDevice.h中的定义如下:
@property(nonatomic,readonly,retain) NSString *uniqueIdentifier __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_2_0,__IPHONE_5_0); // a string unique to each device based on various hardware info.
[self presentModalViewController:myNextViewController animated:YES completion:nil];
UIModalTransitionStyleCoverVertical=0, //默认方式,竖向上推
UIModalTransitionStyleFlipHorizontal, //水平反转
UIModalTransitionStyleCrossDissolve,//隐出隐现
UIModalTransitionStylePartialCurl,//部分翻页效果
} UIModalTransitionStyle;
animation.duration = 1.0;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.type = @"pageCurl";
//animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromLeft;
[self.view.window.layer addAnimation:animation forKey:nil];
kCATransitionFade //淡出
kCATransitionMoveIn //覆盖原图
kCATransitionPush //推出
kCATransitionReveal //底部显出来
SubType:
kCATransitionFromRight
kCATransitionFromLeft // 默认值
kCATransitionFromTop
kCATransitionFromBottom
设置其他动画类型的方法(type):
pageCurl 向上翻一页
pageUnCurl 向下翻一页
rippleEffect 滴水效果
suckEffect 收缩效果,如一块布被抽走
cube 立方体效果
oglFlip 上下翻转效果
9.如何在Label中显示图片
UIImage *image = [UIImage imageNamed:@"321.jpg"];
NSTextAttachment *textAttach = [[NSTextAttachment alloc] init];
textAttach.image = image;
// 2> 使用文本附件创建属性文本
NSAttributedString *strA = [NSAttributedString attributedStringWithAttachment:textAttach];
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- NSLog(@"----%@---",[self decimalwithFormat:@"0.0000" floatV:0.334]);
- NSLog(@"----%@---",[self decimalwithFormat:@"0.0000" floatV:0.334569]);
- NSLog(@"----%@---",[self decimalwithFormat:@"0.0000" floatV:0.334519]);
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- //格式话小数 四舍五入类型
- - (NSString *) decimalwithFormat:(NSString *)format floatV:(float)floatV
- {
- NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
- [numberFormatter setPositiveFormat:format];
- return [numberFormatter stringFromNumber:[NSNumber numberWithFloat:floatV]];
- }
- @end
-
最后控制台打印结果:
[python] view plain copy
- 2014-03-19 15:44:45.262 TestNumberFormatter[3056:60b] ----0.3340---
- 2014-03-19 15:44:45.263 TestNumberFormatter[3056:60b] ----0.3346---
- 2014-03-19 15:44:45.263 TestNumberFormatter[3056:60b] ----0.3345---