Skip to content

Instantly share code, notes, and snippets.

Avatar

Ilter Cengiz iltercengiz

View GitHub Profile
View alternative_button_intrinsic_content_size.m
[self.titleLabel sizeToFit];
CGFloat titleLabelWidth = CGRectGetWidth(self.titleLabel.frame) + margin * 2; // margin from both sides.
CGFloat imageViewWidth = CGRectGetWidth(self.imageView.frame) + margin * 2; // margin from both sides.
CGFloat height = CGRectGetHeight(self.imageView.frame) + CGRectGetHeight(self.titleLabel.frame) + margin * 3; // margin from top and bottom and distance between `imageView` and `titleLabel`.
return CGSizeMake(MAX(titleLabelWidth, imageViewWidth), height);
@iltercengiz
iltercengiz / Constraints.m
Last active Aug 29, 2015
Variable Bindings
View Constraints.m
NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[redView(==blueView)]-0-[blueView]-|"
options:0
metrics:nil
views:@{@"redView": redView,
@"blueView": blueView}];
[self.view addConstraints:constraints];
View editing_changed.m
[self.textField addTarget:self action:@selector(textFieldDidChangeText:) forControlEvents:UIControlEventEditingChanged];
- (IBAction)textFieldDidChangeText:(UITextField *)textField {
NSLog(@"Updated text: %@", textField.text);
}
View DateFormatter.playground
import Foundation
import UIKit
let date = NSDate(timeIntervalSince1970:1426003200)
let dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = .MediumStyle
dateFormatter.stringFromDate(date)
View DateFormatter.playground
import Foundation
import UIKit
let date = NSDate(timeIntervalSince1970:1426003200)
let dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = .MediumStyle
dateFormatter.stringFromDate(date)
View alternative_button_layout.m
self.imageView.frame = (CGRect){.origin = (CGPoint){.x = margin, .y = margin}, .size = (CGSize){.width = imageViewWidth, .height = imageViewWidth}};
self.imageView.center = (CGPoint){.x = CGRectGetWidth(self.frame) / 2.0, .y = imageViewWidth / 2.0 + margin};
[self.titleLabel sizeToFit];
self.titleLabel.frame = (CGRect){.origin = (CGPoint){.x = margin, .y = imageViewWidth + 2 * margin}, .size = self.titleLabel.frame.size};
self.titleLabel.center = (CGPoint){.x = CGRectGetWidth(self.frame) / 2.0, .y = CGRectGetHeight(self.frame) - CGRectGetHeight(self.titleLabel.frame) / 2.0 - margin};
@iltercengiz
iltercengiz / ValidPhoneNumber.m
Created Feb 10, 2015
Checks validation of a given phone number
View ValidPhoneNumber.m
- (BOOL)isValidPhoneNumber:(NSString *)phoneNumberString {
NSError *error = nil;
NBPhoneNumber *phoneNumber = [self.util parse:phoneNumberString defaultRegion:self.region error:&error];
if (error) {
return NO;
} else {
return [self.util isValidNumber:phoneNumber];
@iltercengiz
iltercengiz / Transliterate.m
Last active Aug 29, 2015
Get rid of accented characters
View Transliterate.m
NSString *string = [@"Fıstıkçı Şahap" stringByFoldingWithOptions:NSDiacriticInsensitiveSearch
locale:[NSLocale localeWithLocaleIdentifier:@"en"]];
View DateFormatterExample.playground
// Playground - noun: a place where people can play
import UIKit
import Foundation
let timeInterval = NSDate().timeIntervalSince1970
let date = NSDate(timeIntervalSince1970: timeInterval)
let dateFormatter = NSDateFormatter()