小功能设置 持续更新

2016-07-29  本文已影响31人  雨雪霏霏why

1,阻止tableview下滑操作

    float y = scrollView.contentOffset.y;
    if (y<0) {
        scrollView.alwaysBounceVertical = YES;
    }
}```
####2,让导航栏有毛玻璃效果
`self.navigationController.navigationBar.translucent = YES;`

####3.Cabasicanimation动画退出后台再回来发现动画停止播放解决
`熟悉removedOnCompletion设置为NO即可`
`anim.removedOnCompletion = NO;`

####4.判断是模拟器还是真机
`#if TARGET_IPHONE_SIMULATOR//模拟器`

`#elif TARGET_OS_IPHONE//真机`
   
`#endif`

####5.判断是否允许访问相册和相机

``` if  (NO == [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
            Alert(@"无法查看您的相册,请打开,设置-隐私-照片 来进行设置");
            return;
        }
if (NO == [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
            Alert(@"无法启用您设备的相机功能");
            return;
        }```

####5.过滤掉字符串中的某个字符
``` NSString * str = [[NSString alloc]initWithString:_writeCell.writeTextView.text];
    NSString * subStri = [str stringByReplacingOccurrencesOfString:@"@" withString:@""];//过滤掉@符号
    subStri = [subStri stringByReplacingOccurrencesOfString:@"/" withString:@""];//过滤掉/符号```

####6.判断字符串中是否包含特殊字符(可继续添加)
```+ (BOOL)separteSpecialCharact:(NSString*)str{
    NSRange urgentRange = [str rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@"% %' !?,。‘“”()~¥#&*<>《》()[]{}【】^@/£¤¥|§¨「」『』¢¬ ̄~@#¥&*()——+|《》$_€?.$`;;::"]];
    if (urgentRange.location == NSNotFound) {
        return NO;
    }
    return YES;
}```
####7.button上的字体和图标左对齐
```btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);```

####8.让电池栏隐藏和显示
```必须在infoPlist里面添加View controller-based status bar appearance  NO(如果没有设置  下面的方法会不起作用)```

```再在你需要隐藏和显示的地方调用 [[UIApplication sharedApplication]setStatusBarHidden:YES];```

####9.获取屏幕的尺寸和分辨率
```尺寸 width=[UIScreen mainScreen].bounds.size.width
       height=[UIScreen mainScreen].bounds.size.height
分辨率  CGFloat scale_screen = [UIScreen mainScreen].scale;
width* scale_screen  height* scale_screen```

####10 改变网页的字体大小
```- (void)webViewDidFinishLoad:(UIWebView *)webView{
    NSString *str = @"document.getElementsByTagName('today')[0].style.webkitTextSizeAdjust= '200%'";
    [webView stringByEvaluatingJavaScriptFromString:str];//可根据tag来改变不同位置的字体大小 字体颜色也可改变 或者其他的 主要使用这句话来和js交互
}```

####11.设置web view透明
`[webview setBackgroundColor:[UIColor clearColor]];  
webview.opaque = NO;  `

####12.禁止web view滑动
`webView.scrollView.bounces = NO; //__IPHONE_5_0  
UIScrollView *scrollView = (UIScrollView *)[[webView subviews] objectAtIndex:0];  `
`scrollView.bounces = NO;  `

####13获取web view的高度
```- (void)webViewDidFinishLoad:(UIWebView *)webView1  
{  
    UIScrollView *scrollView = (UIScrollView *)[[webView subviews] objectAtIndex:0];  
    CGFloat webViewHeight = [scrollView contentSize].height;  
    NSString *curHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];  
    CGRect newFrame = webView.frame;  
    newFrame.size.height = webViewHeight;  
    webView.frame = newFrame;   
}```

####14让界面上的键盘消失
`[self.view editing:YES]`
` [[[UIApplication sharedApplication] keyWindow] endEditing:YES];`

####15.模态弹出的试图可自定义大小
`vc.preferredContentSize = CGSizeMake(0.531*kScreenWidth, 0.765*kScreenHeight);(用这个属性preferredContentSize)`

####16.用AFNetworking获取当前的网络状态

``` [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:{
//                [CHObjectClass showMastToast:@"网络无连接!"];
                 [self closeFloatLayerClick];
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWiFi:{
//                [CHObjectClass showMastToast:@"您正在使用WIFI网络"];
                break;
            }
            case AFNetworkReachabilityStatusReachableViaWWAN:{
//                [CHObjectClass showMastToast:@"您正在使用2G/3G网络"];
                break;
            }
            default:
                break;
        }
        //NSLog(@"[[AFNetworkReachabilityManager sharedManager] isReachable] = %d",[[AFNetworkReachabilityManager sharedManager] isReachable]);
        //NSLog(@"网络状态返回: %@", AFStringFromNetworkReachabilityStatus(status));
    }];```
上一篇下一篇

猜你喜欢

热点阅读