참고 : http://stackoverflow.com/questions/5062978/how-can-i-dump-opengl-renderbuffer-to-png-or-jpg-image


-(UIImage *)dumpImage

{

    GLubyte *buffer = (GLubyte *) malloc(backingWidth * backingHeight * 4);

    GLubyte *buffer2 = (GLubyte *) malloc(backingWidth * backingHeight * 4);


    GLvoid *pixel_data = nil;

    glReadPixels(0, 0, backingWidth, backingHeight, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)buffer);


    /* make upside down */


    for (int y=0; y<backingHeight; y++) {

        for (int x=0; x<backingWidth*4; x++) {

            buffer2[y * 4 * backingWidth + x] = buffer[(backingHeight - y - 1) * backingWidth * 4 + x];

        }

    }


    // make data provider from buffer

    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer2, backingWidth * backingHeight * 4, freeImageData);


    // set up for CGImage creation

    int bitsPerComponent = 8;

    int bitsPerPixel = 32;

    int bytesPerRow = 4 * backingWidth;

    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();

    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;

    // Use this to retain alpha

    //CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast;

    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;

    CGImageRef imageRef = CGImageCreate(backingWidth, backingHeight, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);


    // make UIImage from CGImage

    UIImage *newUIImage = [UIImage imageWithCGImage:imageRef];


    return newUIImage;

}


void freeImageData(void *info, const void *data, size_t size) 

{

    //printf("freeImageData called");

    free((void*)data);

}

// 빈 문자열 생성
str3 = [NSString string];


// 문자열로 새로운 문자열 생성
str3 = [NSString stringWithString:@"stringWithString"];
NSLog(@”%@”, str3);

str3 = [[NSString alloc] initWithString:@”initWithString”];
NSLog(@”%@”, str3);
[str3 release];


// 문자열 길이
NSLog(@”length of %@ : %i”, str1, [str1 length]);
NSLog(@”length of %@ : %i”, str2, [str2 length]);


// 문자열 복사
tmp = [NSString stringWithString:str1];
NSLog(@”tmp : %@”, tmp);


// 문자열 합치기 1
tmp = [str1 stringByAppendingString:str2];
NSLog(@”%@ + %@ = %@”, str1, str2, tmp);

// 문자열 합치기 2

NSMutableString *string1 = @"This is";

NSString *string2 = @" a test.";
[string1 appendString:string2];


// 문자열 비교
tmp = str1;
if ( [str1 isEqualToString:tmp] == YES )
NSLog(@”%@ == %@”, tmp, str1);
else
NSLog(@”%@ != %@”, tmp, str1);


// 문자열 비교(대소문자 구분)
compareResult = [str1 compare:str2];
if (compareResult == NSOrderedAscending)
NSLog(@”%@ < %@”, str1, str2);
else if (compareResult == NSOrderedSame)
NSLog(@”%@ == %@”, str1, str2);
else
NSLog(@”%@ > %@”, str1, str2);


// 문자열 비교(대소문자 구분하지 않음)
compareResult = [str1 caseInsensitiveCompare:str2];
if (compareResult == NSOrderedAscending)
NSLog(@”%@ < %@”, str1, str2);
else if (compareResult == NSOrderedSame)
NSLog(@”%@ == %@”, str1, str2);
else
NSLog(@”%@ > %@”, str1, str2);


// 첫문자가 대문자이고 나머지가 소문자인 문자열 리턴
tmp = [str2 capitalizedString];
NSLog(@”%@”, tmp);


// 대문자로 변환
tmp = [str1 uppercaseString];
NSLog(@”%@ -> %@”, str1, tmp);


// 소문자로 변환
tmp = [str2 lowercaseString];
NSLog(@”%@ -> %@”, str2, tmp);


// UTF-8 형식의 문자열 리턴
const char* utf8str = [str1 UTF8String];


// 특정 인덱스의 유니코드 문자 반환
unichar ch = [str2 characterAtIndex:7];
NSLog(@”%c”, ch);


// 특정 인덱스까지의 문자열 반환
tmp = [str1 substringToIndex:15];
NSLog(@”%@”, tmp);


// 특정 인덱스부터 문자열 끝까지 반환
tmp = [str2 substringFromIndex:9];
NSLog(@”%@”, tmp);


// 문자열 중간부분 반환
tmp = [str1 substringWithRange:NSMakeRange(7, 14)];
NSLog(@”%@”, tmp);


// 문자열 내부 검색
range = [str2 rangeOfString:@"Power"];
if (range.location == NSNotFound)
NSLog(@”not found”);
else
NSLog(@”at index %i, length %i”, range.location, range.length);


// 문자열이 특정 문자열로 시작하는지 확인
BOOL bRet = [str1 hasPrefix:@"Obj"];
if (bRet)
NSLog(@”Obj로 시작하는 문자열”);


// 문자열이 특정 문자열로 끝나는지 확인
bRet = [str2 hasSuffix:@"Power"];
if (bRet)
NSLog(@”Power 로 끝나는 문자열”);


// 문자열을 double 값으로 변환
double dblValue = [strNum doubleValue];
NSLog(@”%g”, dblValue);


// 문자열을 float 값으로 변환
float fValue = [strNum floatValue];
NSLog(@”%f”, fValue);


// 문자열을 int 값으로 변환
int iValue = [strNum intValue];
NSLog(@”%i”, iValue);


// 임의의 길이를 가진 빈 문자열 생성
mutableString = [NSMutableString stringWithCapacity:10];
mutableString = [[NSMutableString alloc] initWithCapacity:10];
[mutableString release];

mutableString = [NSMutableString stringWithString:str2];


// 특정 인덱스 위치에 문자열 넣기
[mutableString insertString:@"most " atIndex:9];
NSLog(@”%@”, mutableString);


// 문자열 끝에 새로운 문자열 붙이기
[mutableString appendString:@" dev tool!!"];
NSLog(@”%@”, mutableString);


// 특정 범위 삭제
[mutableString deleteCharactersInRange:NSMakeRange(23, 12)];
NSLog(@”%@”, mutableString);


// 특정 문자열 검색 후 삭제
range = [mutableString rangeOfString:@"Power"];
if (range.location != NSNotFound)
{
[mutableString deleteCharactersInRange:range];
NSLog(@”%@”, mutableString);
}


// 문자열 설정
[mutableString setString:@"xCode is Powerful. "];
NSLog(@”%@”, mutableString);


// 특정 범위를 새로운 문자열로 대치
[mutableString replaceCharactersInRange:NSMakeRange(0, 5) withString:@"Apple xCode"];
NSLog(@”%@”, mutableString);


// 특정 문자를 모두 대치
NSString* searchWord = @”o”;
NSString* replaceWord = @”0″;
[mutableString replaceOccurrencesOfString:searchWord withString:replaceWord options: (NSStringCompareOptions)nilrange:NSMakeRange(0, [mutableString length])];

NSLog(@”%@”, mutableString);



//파일 이름에서 확장자만 따기

[file pathExtension];



//파일 이름에서 확장자만 빼고 가져오기

[file stringByDeletingPathExtension];



//전체 경로에서 파일명만 가져오기

[file lastPathComponent];



//전체 경로에서 파일을 제외한 나머지 경로

[file stringByDeletingLastPathComponent];



//파일 이름에 붙이고 싶은 확장자 붙인 새 String 생성하기

(ext는 물론 NSString* 타입.)

[file stringByAppendingPathExtension:ext];




//특정확장자가 존재하는지 확인하는데에 쓰일수 있다.

[[file stringByDeletingPathExtension] stringByAppendingPathExtension:@"smi"] 

사용자 프레임워크 생성 후 프레임워크 안에 있는 Storyboard를 호출하여 사용해야 할 때가 있다.

그럴땐  NSBundle을 사용하여 Storyboard를 호출할 수 있다.


 Object-C 

NSBundle* frameworkBundle = [NSBundle bundleWithIdentifier:@"com.test.myProject"];

UIViewController* vc = [[UIStoryboard storyboardWithName:@"MyStoryboard" bundle:frameworkBundle] instantiateViewControllerWithIdentifier:@"MyViewController"];


 Swift 

let frameworkBundle = NSBundle(identifier: "com.test.myProject")

let storyboard = UIStoryboard(name: "MyStoryboard", bundle: frameworkBundle)

override func prefersStatusBarHidden() -> Bool {

    return true;

}

'Swift > ' 카테고리의 다른 글

UserDefaults 와 Array  (0) 2017.09.22
텍스트 필드에서 숫자만 입력받기  (0) 2017.09.03
UITextView Placeholder  (0) 2017.08.19
HTTP Networking Framework - Alamofire  (0) 2016.02.03
swiftdoc.org  (0) 2015.01.20


-(BOOL)prefersStatusBarHidden{

    return YES;

}

'Object-C > ' 카테고리의 다른 글

뷰의 터치 이벤트 통과 시키기  (0) 2015.12.16
UIView Rotating  (0) 2015.12.16
ios8에서 sizeWithFont: is now deprecated  (0) 2015.04.07
레티나 단말 확인 방법  (0) 2015.04.07
4inch 모델에서 앱에 검은 여백이 생길때  (0) 2015.04.03

ios8 "sizeWithFont:" 사용 시 deprecated 나타날때 아래와 같이 변경하여 사용하면 된다.

CGSize size = [string sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17.0f]}];

참고 : http://stackoverflow.com/questions/26590096/16-pixels-margin-left-and-right-on-uiview-created-with-autolayout


autolayout 사용하였을 때 단말에 따라 좌/우 또는 위/아래에 여백이 생기는 경우가 있다



해당 뷰를 선택 후 "Constrain to margins"체크 해제 후 확인 해 보면 좌우 여백이 없어 졌을 것 이다.


'Autolayout' 카테고리의 다른 글

Autolayout을 도와주는 snapkit  (0) 2018.01.22

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) {
// RETINA DISPLAY
}

+ Recent posts