This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// Define the input string with placeholders | |
String inputString = "Hello, %@! How are you, %@, %@?"; | |
// Define an array of replacement strings | |
List<String> replacements = ["Alice", "Bob"]; | |
print(replaceInString(inputString, replacements)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<style> | |
.block { | |
display: block; | |
width: 100%; | |
border: none; | |
background-color: #04AA6D; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension String { | |
func qrCode() -> UIImage? { | |
if self.isEmpty { return nil } | |
let data = self.data(using: String.Encoding.ascii) | |
if let filter = CIFilter(name: "CIQRCodeGenerator") { | |
filter.setValue(data, forKey: "inputMessage") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; | |
NSDictionary *stringAttributes = @{ | |
NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:13], | |
NSForegroundColorAttributeName: [UIColor colorWithHexString:@"4C4C4C"] | |
}; | |
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"Text" | |
attributes:stringAttributes]; | |
NSData *rtfData = [attributedString dataFromRange:NSMakeRange(0, attributedString.length) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import <UIKit/UIKit.h> | |
@interface NSMutableAttributedString (setFontButSaveStyle) | |
- (void)setFontButSaveStyle:(UIFont *)font; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by Kirill Pyulzyu on 19.08.15. | |
// Copyright (c) 2015 Kirill Pyulzyu. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface UILabelWithInsets : UILabel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define IS_LANDSCAPE_ORIENTATION (UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) | |
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) | |
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0) | |
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width) | |
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height) | |
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT)) | |
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT)) | |
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; | |
if(authStatus == AVAuthorizationStatusAuthorized) { | |
// do your logic | |
} else if(authStatus == AVAuthorizationStatusDenied){ | |
// denied | |
} else if(authStatus == AVAuthorizationStatusRestricted){ | |
// restricted, normally won't happen | |
} else if(authStatus == AVAuthorizationStatusNotDetermined){ | |
// not determined?! | |
[AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)drawRect:(CGRect)rect { | |
[super drawRect:rect]; | |
CGContextRef context = UIGraphicsGetCurrentContext(); | |
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); | |
// Draw them with a 2.0 stroke width so they are a bit more visible. | |
CGContextSetLineWidth(context, 2.0f); | |
CGContextMoveToPoint(context, 0.0f, 0.0f); //start at this point |
NewerOlder