info

category : objective-c
[objective-c]UIWebViewのhtmlにUIImageをimgタグで表示  @ App Develop , objective-c 2014年11月18日
UIWebViewのhtmlにUIImageをimgタグで表示
NSData *imageData = UIImagePNGRepresentation(image);
NSString* base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding76CharacterLineLength];
base64 = [base64 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString*js = [NSString stringWithFormat:@"var img=document.createElement('img');img.src='data:image/jpg;base64,%@';document.body.appendChild(img);",base64];
[mainWebView stringByEvaluatingJavaScriptFromString:js];
[objective-c]UIWebViewでリンククリックで処理  @ App Develop , objective-c 2014年11月17日
UIWebViewでリンククリックで処理

読み込むhtml
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<a href="js-call://camera">camera</a><br/><br/>
<a href="js-call://album">album</a><br/><br/>
<a href="js-call://alert">alert</a><br/><br/>
</body>
</html>

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSLog(@"shouldStartLoadWithRequest");
    NSString *requestString = [[request URL] absoluteString];
    NSString *protocol = @"js-call://";
    if ([requestString hasPrefix:protocol]) {
        NSString *requestContent = [requestString substringFromIndex:[protocol length]];
        NSArray *vals = [requestContent componentsSeparatedByString:@"/"];
        if ([vals[0] isEqualToString:@"camera"]){
            [self startCamera];//カメラ起動
        }else if ([vals[0] isEqualToString:@"album"]){
            [self startAlbum];//カメラロール起動
        }else {
            [webView stringByEvaluatingJavaScriptFromString:@"alert('Not defined');"];//jsのalert実行
        }
        return NO;
    }
    return YES;
}
[objective-c]UIViewをUIImageへ(Retina対応)  @ App Develop , objective-c 2014年10月3日
UIViewをUIImageへ(Retina対応)
-(UIImage*)getUIImageByUIView:(UIView*)view
{
    UIImage *screenImage;
    //UIGraphicsBeginImageContext(size);
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    screenImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return screenImage;
}
[objective-c]UILabelを複製する  @ App Develop , objective-c 2014年7月14日
UILabelを複製する
-(UILabel*)getCloneUILabelByUILabel:(UILabel*)label
{
    NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject:label];
    return [NSKeyedUnarchiver unarchiveObjectWithData:archivedData];
}
UILabel*cloneLabel = [self getCloneUILabelByUILabel:modelLabel];
[objective-c]2つの日付の差を日数で出す  @ App Develop , objective-c 2014年5月29日
2つの日付の差を日数で出す
int dayCount = [self getDaysCountByTwoDateString:@"2014-04-01" endDateString:@"2014-04-04"];
-(int)getDaysCountByTwoDateString:(NSString*)startDateString endDateString:(NSString*)endDateString
{
    NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init];
    [inputDateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSDate *startInputDate = [inputDateFormatter dateFromString:startDateString];
    NSDate *endInputDate = [inputDateFormatter dateFromString:endDateString];
    
    float tmp= [endInputDate timeIntervalSinceDate:startInputDate];
    int day=(int)( tmp / (3600.0*24.0) );
    return day;
}
[objective-c]animateWithDurationを途中で止める  @ App Develop , objective-c 2014年5月16日
animateWithDurationを途中で止める

アニメーション実行
[UIView animateWithDuration:10.0f animations:^{
    targetView.frame=CGRectMalke(0.0,0.0,100.0,100.0);
} completion:^(BOOL finished) {
    
}];

アニメーション中止
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView animateWithDuration:0.001 animations:^{
    targetView.alpha = 1.0;
}];