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 / 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 / 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 / ViewController.swift
Created February 28, 2018 10:56 — forked from soggybag/ViewController.swift
Animate drawing sine wave. CABasicAnimation and UIBezierPath
// Draw a sine curve with a fill
let centerY = frame.height / 2 // find the vertical center
let steps = 200 // Divide the curve into steps
let stepX = frame.width / CGFloat(steps) // find the horizontal step distance
// Make a path
let path = UIBezierPath()
path.moveToPoint(CGPoint(x: 0, y: centerY))
// Loop and draw steps in straingt line segments
@prat14k
prat14k / UILabelCountLines.swift
Last active June 2, 2023 17:43 — forked from fuxingloh/UILabelCountLines.swift
iOS Swift: How to check if UILabel is truncated? Calculate number of lines for UILabel
func countLabelLines(label: UILabel) -> Int {
// Call self.layoutIfNeeded() if your view uses auto layout
let myText = label.text! as NSString
let rect = CGSize(width: label.bounds.width, height: CGFloat.greatestFiniteMagnitude)
let labelSize = myText.boundingRect(with: rect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: label.font], context: nil)
return Int(ceil(CGFloat(labelSize.height) / label.font.lineHeight))
}
@prat14k
prat14k / remove-bottom-line-navbar.md
Created June 22, 2018 07:56 — forked from vinhnx/remove-bottom-line-navbar.md
remove 1px bottom line of the navigation bar

If you just want to use a solid navigation bar color and have set this up in your storyboard, use this code in your AppDelegate class to remove the 1 pixel border via the appearance proxy:

Objective-C

[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init]
                                  forBarPosition:UIBarPositionAny
                                      barMetrics:UIBarMetricsDefault];

[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
@prat14k
prat14k / P12toPEM.txt
Created June 28, 2018 09:53 — forked from shahdhiren/P12toPEM.txt
Convert P12 file for Push Notification to PEM format
Development Phase:
Step 1: Create Certificate .pem from Certificate .p12
Command: openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
Step 2: Create Key .pem from Key .p12
Command : openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
Step 3: Optional (If you want to remove pass phrase asked in second step)
Command : openssl rsa -in apns-dev-key.pem -out apns-dev-key-noenc.pem
@prat14k
prat14k / WiFiSsid.swift
Created July 18, 2018 06:15 — forked from werediver/WiFiSsid.swift
Get the connected Wi-Fi network SSID on iOS (in Swift).
import Foundation
import SystemConfiguration.CaptiveNetwork
func getWiFiSsid() -> String? {
var ssid: String?
if let interfaces = CNCopySupportedInterfaces() as NSArray? {
for interface in interfaces {
if let interfaceInfo = CNCopyCurrentNetworkInfo(interface as! CFString) as NSDictionary? {
ssid = interfaceInfo[kCNNetworkInfoKeySSID as String] as? String
break
@prat14k
prat14k / morphing.swift
Last active July 27, 2018 11:08 — forked from AliSoftware/morphing.swift
A simple demo of doing some morphing using CAShapeLayer & UIBezierPath. Animation done using CABasicAnimation.
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
func addLabel() {
let label = UILabel()
label.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
label.text = "Hello World!"
label.textColor = .black
@prat14k
prat14k / remove_tuxera.sh
Created July 26, 2018 07:45 — forked from miguelmota/remove_tuxera.sh
Completely uninstall and remove Tuxera NTFS on MacOs (resets trial version)
rm -rf /Applications/Tuxera\ Disk\ Manager.app
rm -rf /Library/Application\ Support/Tuxera\ NTFS
rm -rf /Library/Filesystems/fusefs_txantfs.fs