美文网首页iOS Developer - TipsiOS移动开发iOS开发
把UIView变为UIImage, url 转码, iOS9.0

把UIView变为UIImage, url 转码, iOS9.0

作者: Stark_Dylan | 来源:发表于2015-08-28 12:02 被阅读608次

- (UIImage*) imageWithUIView:(UIView*) view{
    // 创建一个bitmap的context  
    // 并把它设置成为当前正在使用的context  
    UIGraphicsBeginImageContext(view.bounds.size);  
    CGContextRef currnetContext = UIGraphicsGetCurrentContext();
    //[view.layer drawInContext:currnetContext];
    [view.layer renderInContext:currnetContext];
    // 从当前context中创建一个改变大小后的图片  
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();  
    // 使当前的context出堆栈  
    UIGraphicsEndImageContext();  
    return image;
}

// 如果含有中文,将url的中文转码
        NSString *string = value;
        BOOL containChinese = NO;
        for(int i=0; i< [string length];i++){
            int a = [string characterAtIndex:i];
            if( a > 0x4e00 && a < 0x9fff) {
                containChinese = YES;
                break;
            }
        }
        if (containChinese) {
            // 含中文的情况
            self.url = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        } else {
            // 不含中文
            self.url = string;
        }
在Info.plist中添加NSAppTransportSecurity类型Dictionary。
在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES
if (flags & kSCNetworkReachabilityFlagsIsWWAN) {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
                NSString *currentRadioAccessTechnology = info.currentRadioAccessTechnology;
                if (currentRadioAccessTechnology) {
                    if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyLTE]) {
                        return kReachableVia4G;
                    } else if ([currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyEdge] || [currentRadioAccessTechnology isEqualToString:CTRadioAccessTechnologyGPRS]) {
                        return kReachableVia2G;
                    } else {
                        return kReachableVia3G;
                    }
                }
            }

if ((flags & kSCNetworkReachabilityFlagsTransientConnection) == kSCNetworkReachabilityFlagsTransientConnection) {
if((flags & kSCNetworkReachabilityFlagsConnectionRequired) == kSCNetworkReachabilityFlagsConnectionRequired) {
                    return kReachableVia2G;
                }
                return kReachableVia3G;
            }
return kReachableViaWWAN;
        }

相关文章

网友评论

    本文标题:把UIView变为UIImage, url 转码, iOS9.0

    本文链接:https://www.haomeiwen.com/subject/kthkcttx.html