Burak Üstün

Code Samples

List of Content

Horizontal Scroll View
Pull to Refresh
Share Instagram
Initilazier
Action Sheet With Photo Camera & Photo Gallery
Create a File
Light Status Bar
Dynamic Cell Height
WSDL2Code
AFNetworking Upload



Horizontal Scroll View

-(void)RenkScrollOlustur{
    NSInteger viewcount= [arrayKategoriID count];
    for (int i = 0; i < viewcount; i++)
    {
            UIImageView *renk =[[UIImageView alloc] initWithFrame:CGRectMake(i * 53, 0, 44, 44)];
            [renk sd_setImageWithURL:[NSURL URLWithString:[arrayKategoriResim objectAtIndex:i]]];
            renk.tag = i;
            renk.userInteractionEnabled = YES;
            tap.numberOfTapsRequired = 1;
            [renk addGestureRecognizer:tap];
            [_scrollRenkler addSubview:renk];

        for (int i = 0; i < viewcount; i++)
        {
            NSString *item = [arrayKategoriResim objectAtIndex:i];
            
            if (item.length > 0)
            {
                UIView *dot = [[UIImageView alloc] initWithFrame:CGRectMake((i + 1) * 44 + (9 * i) + 2, 5, 5, 34)];
                [_scrollRenkler addSubview:dot];
            }
        }
    }
    _scrollRenkler.showsHorizontalScrollIndicator = NO;
    _scrollRenkler.contentSize = CGSizeMake(44 * viewcount, 44);
}

- (void)viewTapped:(UITapGestureRecognizer*)tap{
    UIView *view = (UIView *)tap.view;
    int tiklananIndex = view.tag;
    int deneme = [[arrayKategoriID objectAtIndex:tiklananIndex] intValue];
    [self VeriCek:deneme];
    /*
    MarkaDetay* infoController = [self.storyboard instantiateViewControllerWithIdentifier:@"MarkaDetayID"];
    infoController.selectedID = img.tag;
    
    infoController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:infoController animated:YES completion:nil];
    */
}

#ScrollView #Objective-C




Pull To Refresh

Load içerisine

refreshControl = [[UIRefreshControl alloc] init];
    refreshControl.backgroundColor = [UIColor whiteColor];
    refreshControl.tintColor = [UIColor blackColor];
    [_madalyalarTable addSubview:refreshControl];
    [refreshControl addTarget:self
                            action:@selector(VeriCek)
                  forControlEvents:UIControlEventValueChanged];

Veri Çek fonksiyonu :

-(void)VeriCek
{
 [_madalyalarTable reloadData];
    if (refreshControl) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"MMM d, h:mm a"];
        NSString *title = [NSString stringWithFormat:@"Son Güncelleme: %@", [formatter stringFromDate:[NSDate date]]];
        NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIColor blackColor]                                                           forKey:NSForegroundColorAttributeName];
        NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrsDictionary];
        refreshControl.attributedTitle = attributedTitle;
        [refreshControl endRefreshing];
    }
}

Veri yoksa uyarı:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    if ([array count]) {
        
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        return 1;
    } else {
        // Display a message when the table is empty
        UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
        messageLabel.text = @"No data is currently available. Please pull down to refresh.";
        messageLabel.textColor = [UIColor blackColor];
        messageLabel.numberOfLines = 0;
        messageLabel.textAlignment = NSTextAlignmentCenter;
        messageLabel.font = [UIFont fontWithName:@"Palatino-Italic" size:20];
        [messageLabel sizeToFit];
        self.tableView.backgroundView = messageLabel;
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return 0;
}




Share Instagram

pod ‘AQSInstagramActivity’

- (IBAction)btnPaylas_Click:(id)sender {
    UIActivity *instagramActivity = [[AQSInstagramActivity alloc] init];
    UIImage *imageToShare = _MainImage.image;
    NSArray *objectsToShare = @[imageToShare];
    
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:@[instagramActivity]];
    
    NSArray *excludeActivities = @[UIActivityTypeAirDrop,
                                   UIActivityTypePrint,
                                   UIActivityTypeAssignToContact,
                                   UIActivityTypeAddToReadingList,
                                   UIActivityTypePostToFlickr,
                                   UIActivityTypePostToVimeo];
    activityVC.excludedActivityTypes = excludeActivities;
    
    [self presentViewController:activityVC animated:YES completion:nil];
}



Initilazier

-(id)initWithData:(NSString *)menuItem fPath:(NSString *)fotoString
{
    self = [super init];
    if (self) {
        self.MenuItem = menuItem;
        self.FotoString = fotoString;
    }
    return self;
}



First create Action Sheet

-(void)createActionSheet{
    UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Fotoğraf Galerisi", nil];
    
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        [popup addButtonWithTitle:@"Fotoğraf Kamerası"];
    
    [popup addButtonWithTitle:@"Vazgeç"];
    popup.cancelButtonIndex = popup.numberOfButtons - 1;
    [popup showInView:[UIApplication sharedApplication].keyWindow];
}

Then handle the button clicks

- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
        [self openPhotoAlbum];
    else if (popup.numberOfButtons == 3 && buttonIndex == 1)
        [self showCamera];
}

Photo camera and photo album functions are below

- (void) showCamera
{
    UIImagePickerController *controller = [[UIImagePickerController alloc] init];
    controller.delegate = self;
    controller.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:controller animated:YES completion:nil];
}


- (void) openPhotoAlbum
{
    UIImagePickerController *controller = [[UIImagePickerController alloc] init];
    controller.navigationBar.tintColor= [UIColor whiteColor];
    controller.navigationBar.titleTextAttributes =  [NSDictionary dictionaryWithObjectsAndKeys:
                                                   [UIColor whiteColor], NSForegroundColorAttributeName,nil];
    controller.delegate = self;
    controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    
    [self presentViewController:controller animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    self.mImage = image;
    
    
    [picker dismissViewControllerAnimated:YES completion:^{
        //Completion Handler
    }];
}



Create a File

Create unique file name

-(NSString *)CreatFileName
{
    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyyMddHHmmss"];
    return [dateFormatter stringFromDate:[NSDate date]];
}

Create file with image

-(void)CreateFileWithImage:(UIImage *)image
{
    NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    NSString *dosyaAdi = [NSString stringWithFormat:@"%@.png", [self CreatFileName]];
    NSString *filePath = [documentDir stringByAppendingPathComponent:dosyaAdi];
    NSData *imageData = UIImagePNGRepresentation(image);
    [[NSFileManager defaultManager] createFileAtPath:filePath contents:imageData attributes:nil];
}



Light Status Bar

-(UIStatusBarStyle)preferredStatusBarStyle{
    [super preferredStatusBarStyle];
    return UIStatusBarStyleLightContent;
}



Dynamic Cell Height

Label’ın uzunluğunu almak için :

-(CGFloat)getHeight: (NSString*) text{
    CGFloat width = Content.width;
    UIFont *font = [UIFont fontWithName:@"FONT ADI" size:18];
    NSAttributedString *attributedText =
    [[NSAttributedString alloc] initWithString:text
                                    attributes:@{NSFontAttributeName: font}];
    CGRect rect = [attributedText boundingRectWithSize:(CGSize){width, CGFLOAT_MAX}
                                               options:NSStringDrawingUsesLineFragmentOrigin
                                               context:nil];
    CGSize size = rect.size;
    CGFloat height = ceilf(size.height);
    return height;
}

heightForRowAtIndexPath fonksiyonu ise aşağıdaki gibi olacak MinTableHeight global olarak tanımlanıp minimum hücre uzunluğu verilecek.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *text = [[arrayVideo objectAtIndex:indexPath.row] videoName];
    if([self getHeight:text] > MinTableHeight)
        return [self getHeight:text];
    return MinTableHeight;
}



WSDL 2 Code

1- Project Target Build Phases gidin ve libxml2.lib yi ekleyin

Project Settings’e gidin ve “Header Search Paths” - $(SDK_DIR)”/usr/include/libxml2 ekleyin.
(Build Phases > Link Binary with Libraries.
“Other” butonuna basın.
Dosya seçim ekranı geldikten sonra ise “CMD”+”Shift”+”G” ‘ye basın
“/usr/lib/” yazın
“libxml2.2.dylib” yi seçin.

2- http://www.apphic.com/IOSLibrary/WSDL2Code.zip adresindeki klasorleri projeye ekle (ARC olmadigi icin XPathQuery.m ve NSData+Base64.m icin Build Phases de Compile Sources icinde : -fno-objc-arc tanimla )

3- http://www.wsdl2code.com/pages/Home.aspx sayfasinda sonu WDSL ile biten webservice linkini kopyala ve iOS arc icin al. Bu ciktiyi projeye ekle. (myerdem86 12991923Ab)

4- Kullanacagin sayfanin .h icine bunlari : #import “ServiceProxy.h” Wsdl2CodeProxyDelegate @property (nonatomic,retain) ServiceProxy* service;

Kullanacagin sayfanin.m icinde su 2 fonksiyonu ekle //if service recieve an error this method will be called

-(void)proxyRecievedError:(NSException*)ex InMethod:(NSString*)method{
    NSLog(@"Exeption in service %@",method);
}
//proxy finished, (id)data is the object of the relevant method service
-(void)proxydidFinishLoadingData:(id)data InMethod:(NSString*)method{
    NSLog(@"Service %@ Done!",method);




    NSArray *array = (NSArray *)data;
    
    for (int i = 0; i < array.count; ++i)
    {
        fI *item = (fI *)[array objectAtIndex:i];
        //...
    }
}

Ornek bir fonk. cagrisi :

self.service = [[ServiceProxy alloc]initWithUrl:@"http://isilti.apphic.com/service.asmx" AndDelegate:self];
[self.service getFList:1 :0];



AFNetworking Upload

    NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    NSString *filePath = [documentDir stringByAppendingPathComponent:_Path];
    UIImage *Image= [UIImage imageWithContentsOfFile:filePath];
    NSMutableDictionary* paramaters = [[NSMutableDictionary alloc] init];
    [paramaters setObject:[NSString stringWithString:@"Foo" forKey:@"Bar"];
    NSData *fileData = Image?UIImageJPEGRepresentation(Image, 0.5):nil;
    NSError *error;
    NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"URL" parameters:paramaters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        if(fileData){
            [formData appendPartWithFileData:fileData
                                        name:@"uploadedfile"
                                    fileName:@"img.jpeg"
                                    mimeType:@"multipart/form-data"];
        }
    } error:&error];
    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSURLSessionUploadTask *uploadTask;
    uploadTask = [manager uploadTaskWithStreamedRequest:request progress:^(NSProgress * _Nonnull uploadProgress) {
        NSLog(@"Wrote %f", uploadProgress.fractionCompleted);
    }
                                      completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
                                         //Handle Response
                                      }];
    [uploadTask resume];
}

February 16, 2017