OC 开发当中的一些小技巧(持续更新ing)

来源:互联网 发布:老k平面户型优化设计 编辑:程序博客网 时间:2024/05/16 15:29
http访问解决方案(17年后苹果新规执行之后,这种方法可能会对APP审核造成困扰)

<key>NSAppTransportSecurity</key>

<dict>    

<key>NSAllowsArbitraryLoads</key>   

 <true/>

</dict>


屏幕方向改变
- (BOOL)shouldAutoratoteToInterfaceOrientation:(UIInterfaceOritentation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOritationprotraint);
}

获取故事版内容
self.vc = [story instantiateViewControllerWithIdentifier:VCIdentifier];//VCIdentifier是宏定义字符串

状态栏的设置
[UIApplication sharedApplication].statusBarStyle =UIStatusBarStyleLightContent;//有可能会和iOS版本出现问题

获取网络类型(私有API)
.m
{
id dataView;
}

- (void)getNetworkingStatus{//私有方法

    NSArray *subViews = [[[[UIApplication sharedApplication] valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];//获取前台页面的状态栏,注意如果隐藏了状态,此处无法取值。

//快枚举遍历状态栏视图集合,查找到需要的网络类型视图并存储

    [subViewsenumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx,BOOL *_Nonnull stop) {

        if([obj isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]){

            dataView = obj;

        }

    }];

    

    switch ([[dataView valueForKey:@"dataNetworkType"] integerValue]) {

        case 0:NSLog(@"no wifi");break;

       case1:NSLog(@"2G");break;

       case2:NSLog(@"3G");break;

            

       default:NSLog(@"wifi");break;

            break;

    }

}



导航栏透明设置:


//导航栏全透明设置ß

- (void)setNavigationBarType{

    self.tabBarController.tabBar.hidden = YES;

    

    self.navigationController.navigationBar.translucent = YES;

    UIColor *col = [UIColor clearColor];

    CGRect rec = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64);

    

    UIGraphicsBeginImageContext(rec.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, col.CGColor);

    CGContextFillRect(context, rec);

    

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

    self.navigationController.navigationBar.clipsToBounds = YES;

}




//导航栏全透明设置ß

- (void)setNavigationBarType{

    self.tabBarController.tabBar.hidden = YES;

    

    self.navigationController.navigationBar.translucent = YES;

    UIColor *col = [UIColor clearColor];

    CGRect rec = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), 64);

    

    UIGraphicsBeginImageContext(rec.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, col.CGColor);

    CGContextFillRect(context, rec);

    

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];

    self.navigationController.navigationBar.clipsToBounds = YES;

}


1 0
原创粉丝点击