본문 바로가기
반응형

obj-c6

iOS iP주소 가져오기 #import #include #include #include #pragma mark - #pragma mark IP주소 가져오기 - (NSString *)getIPAddress { struct ifaddrs *interfaces = NULL; struct ifaddrs *temp_addr = NULL; NSString *wifiAddress = nil; NSString *cellAddress = nil; // retrieve the current interfaces - returns 0 on success if(!getifaddrs(&interfaces)) { // Loop through linked list of interfaces temp_addr = interfaces; while(temp_add.. 2019. 5. 30.
UIImage 이미지 자르기 - (UIImage*)imageByCropping:(UIImage *)imageToCrop toRect:(CGRect)rect { CGImageRef imageRef = CGImageCreateWithImageInRect([imageToCrop CGImage], rect); UIImage *cropped = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); return cropped; } 2019. 5. 30.
UIImage에 여백 마진 넣기 - (UIImage *)imageWithInsets:(CGRect)insetRect image:(UIImage *)image { CGRect newRect = CGRectMake(0.0, 0.0, insetRect.origin.x+insetRect.size.width+image.size.width, insetRect.origin.y+insetRect.size.height+image.size.height); // Setup a new context with the correct size UIGraphicsBeginImageContextWithOptions(newRect.size, NO, 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); UIGraph.. 2019. 5. 30.
NSDictionary 또는 NSArray에서 JSON 문자열을 생성 하기 NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:contentDictionary options:NSJSONWritingPrettyPrinted error:&error]; NSString *jsonString; if (jsonData) { jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; } else { NSLog(@"Got an error: %@", error); jsonString = @""; } NSLog(@"Your JSON String is %@", jsonString); 2019. 5. 30.
선택된 셀의 인덱스 불러오기 Swift func addItem(sender: UIButton) { var touchPoint = sender.convert(CGPoint.zero, to: self.maintable) // maintable --> replace your tableview name var clickedButtonIndexPath = maintable.indexPathForRow(at: touchPoint) NSLog("index path.section ==%ld", Int(clickedButtonIndexPath.section)) NSLog("index path.row ==%ld", Int(clickedButtonIndexPath.row)) }​ Obj-C CGPoint touchPoint = [sender conve.. 2019. 5. 30.
배열을 원하는 갯수 만큼 나누기 숫자 1~20까지 들어있는 배열을 3개씩 나눠서 여러개의 배열로 나눈다. NSArray *array = @[@"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", @"13", @"14", @"15", @"16", @"17", @"18", @"19", @"20", ]; NSMutableArray *testArray = [NSMutableArray new]; int batchSize = 3; for(int j = 0; j < [array count]; j += batchSize) { NSArray *subarray = [array subarrayWithRange:NSMakeRange(j, MIN(batchSize, [array c.. 2019. 5. 30.
반응형