Skip to content

Instantly share code, notes, and snippets.

View prat14k's full-sized avatar
🏠
Working from home

Prateek Sharma prat14k

🏠
Working from home
View GitHub Profile
@prat14k
prat14k / objectivecMethod.m
Last active December 19, 2017 12:26
Objective-c Code to get word from a UITextView
-(NSString *)getWordAtPosition:(CGPoint)pos inTextView:(UITextView*)_tv
{
UITextView *tempTextview = [[UITextView alloc]init];
tempTextview.text = temmp;
//eliminate scroll offset
pos.y += _tv.contentOffset.y;
//get location in text from textposition at point
UITextPosition *tapPos = [_tv closestPositionToPoint:pos];
@prat14k
prat14k / stringMethod.swift
Created December 20, 2017 09:55
Compare string character to space or any other character
var s = "X yz"
for var i = 0; i < s.characters.count; i++ {
let x = s[s.startIndex.advancedBy(i)]
print(x)
print(String(x) == " ")
}
for c in s.characters {
print(c)
print(String(c) == " ")
@prat14k
prat14k / shimmer.html
Created December 20, 2017 12:10
Shimmer like effect
<html><head><title>Blank Loader</title></head><body><div class=\"outer_container\"><div class=\"loader\"></div></div><style>html, body { margin:0; padding:0;background:rgba(0,0,0,0);}.outer_container { background:rgba(0,0,0,0);width:100%;overflow:hidden; position:relative}.loader {width: 90px;height: 2.5px;background: #2b2b2b;box-shadow: 0 0 80px 60px #000;animation: load 1.0s infinite;transition:all 1.0s ease-in-out;margin-left:0;}@keyframes load {0% {margin-left:-200px;}100% { margin-lefT:120%}}</style></body></html>
@prat14k
prat14k / textHeight.m
Created December 29, 2017 06:48 — forked from brennanMKE/textHeight.m
Text Height in Objective-C for NSString and NSAttributedString
- (CGFloat)heightForAttributedString:(NSAttributedString *)text maxWidth:(CGFloat)maxWidth {
if ([text isKindOfClass:[NSString class]] && !text.length) {
// no text means no height
return 0;
}
NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
CGSize size = [text boundingRectWithSize:CGSizeMake(maxWidth, CGFLOAT_MAX) options:options context:nil].size;
@prat14k
prat14k / Could not find Developer Disk Image
Created December 29, 2017 06:55
XCode Bug : Could not find Developer Disk Image
Could not find Developer Disk Image :
I personally downloaded Xcode 6.4 beta and 7.0 beta and I was very happy to find the solution by searching "8.4" inside the application folder of the 6.4 beta. By doing this, I found the folder 8.4 (12H4125a) containing the iOS 8.4 image and I copied this folder to the same path of the 7.0 beta. The path is the following:
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
When you will reopen Xcode 7 and choose your device, there will be an error message; just click on fix issue and that should do it!
@prat14k
prat14k / gist:283bb06e81ac0dcf3419f002ba1ccc09
Created January 5, 2018 11:55
objc File Manupulation methods
- (void)writeStringToFile:(NSString*)aString {
// Build the path, and create if needed.
NSString* filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* fileName = @"bookmark.json";
NSString* fileAtPath = [filePath stringByAppendingPathComponent:fileName];
if (![[NSFileManager defaultManager] fileExistsAtPath:fileAtPath]) {
[[NSFileManager defaultManager] createFileAtPath:fileAtPath contents:nil attributes:nil];
}
@prat14k
prat14k / remove_cursor.m
Created January 15, 2018 09:42 — forked from mjjimenez/remove_cursor.m
Remove cursor from UITextField
//Subclass UITextfield and Override the - (CGRect)caretRectForPosition:(UITextPosition *)position //method and return CGRectZero.
- (CGRect)caretRectForPosition:(UITextPosition *)position {
return CGRectZero;
}
@prat14k
prat14k / UILabel+dynamicSizeMe.h
Created January 30, 2018 06:32 — forked from danielphillips/UILabel+dynamicSizeMe.h
Adjust UILabel to change it's frame according to it's content
@interface UILabel (dynamicSizeMe)
-(float)resizeToFit;
-(float)expectedHeight;
@end
@prat14k
prat14k / emailValidation.m
Created February 1, 2018 09:24
Email Validation Method using a regex in Objc
-(BOOL) isValidEmail:(NSString *)checkString
{
BOOL stricterFilter = NO;
NSString *stricterFilterString = @"^[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$";
NSString *laxString = @"^.+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2}[A-Za-z]*$";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:checkString];
}
@prat14k
prat14k / scroll.swift
Created February 1, 2018 13:01
bring textfield above keyboard in a scrollview
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
let textfieldPos = scrollView.convert(textField.frame.origin, to: view).y
let textFieldHght = textField.frame.size.height
let scrollViewHght = scrollView.frame.size.height
if (textfieldPos + textFieldHght) > (scrollViewHght - 250) {
var duration : Double
if isKeyBoardVisible {