Skip to content

Instantly share code, notes, and snippets.

View MadeBugs's full-sized avatar

J.M MadeBugs

View GitHub Profile
@MadeBugs
MadeBugs / view.css
Last active March 14, 2019 08:53
水平垂直居中
.view {
display: flex;
align-items: center;
justify-content: center;
}
@MadeBugs
MadeBugs / StringEncode.m
Last active October 24, 2024 03:32
特殊字符转码
//特殊字符转码
- (NSString *)encodeWithString:(NSString *)string {
NSString *charactersToEscape = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\| ";
NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];
return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
}
//URL中包含中文的连接转码
NSString *escapedPath = [@"http://www.baidu.com?中文" stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
@MadeBugs
MadeBugs / DynamicChangeIcon.m
Created March 23, 2019 08:55
动态更换APP图标
//判断是否支持更换图标
if(![[UIApplication sharedApplication] supportsAlternateIcons]) {
return;
}
//更换icon,传入图标文件名
[[UIApplication sharedApplication] setAlternateIconName:@"shuiguo" completionHandler:^(NSError * _Nullable error) {
}];
@MadeBugs
MadeBugs / AirPrint.m
Created March 29, 2019 01:17
Airprint
- (void)testAirPrint{
UIPrintInteractionController *pic = [UIPrintInteractionController sharedPrintController];
pic.delegate = self;
UIPrintInfo *printInfo = [UIPrintInfo printInfo];
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = self.webView.URL.scheme;
pic.printInfo = printInfo;
UIViewPrintFormatter *viewFormatter = [self.webView viewPrintFormatter];
@MadeBugs
MadeBugs / HTMLToPDF.m
Created April 2, 2019 05:55
HTML网页导出PDF文件
- (void)htmlExpectToPDF{
UIViewPrintFormatter *viewPrintFormatter = [self.webView viewPrintFormatter];
viewPrintFormatter.startPage = 0;
UIPrintPageRenderer *pageRender = [[UIPrintPageRenderer alloc] init];
[pageRender addPrintFormatter:viewPrintFormatter startingAtPageAtIndex:0];
CGRect page;
page.origin.x=0;
@MadeBugs
MadeBugs / getSize.m
Created April 22, 2019 03:36
计算文字高度
CGSize size = [info[@"entry"] boundingRectWithSize:CGSizeMake(260, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
@MadeBugs
MadeBugs / xcodeBuild++.sh
Last active July 6, 2019 08:02
xcode build version 自增
if [ $CONFIGURATION == Debug ]; then
echo "当前为 Release Configuration,开始自增 Build"
plist=${INFOPLIST_FILE}
buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}")
if [[ "${buildnum}" == "" ]]; then
echo "Error:在Plist文件里没有 Build 值"
exit 2
fi
buildnum=$(expr $buildnum + 1)
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $buildnum" "${plist}"
@MadeBugs
MadeBugs / shoutScreenView.swift
Last active July 19, 2019 08:18
获取当前屏幕截图
// 截取屏幕生成UIImage
func shoutScreen() -> UIImage {
let render = UIGraphicsImageRenderer(size: (window?.bounds.size)!)
let image = render.image { (ctx) in
window?.drawHierarchy(in: window!.bounds, afterScreenUpdates: false)
}
return img
}
// 如果是系统的弹窗,则无法获取到,比如在用Airprint,这时是无法获取到的,结果为nil
func getPrexxx() -> UIViewController {
var result = UIApplication.shared.keyWindow?.rootViewController
while ((result?.presentedViewController) != nil) {
result = result?.presentedViewController
}
return result
}
@MadeBugs
MadeBugs / demo.swift
Created July 29, 2019 06:29
textView设置placeholder
//要先添加到view上,不然不显示,
TextView.addSubview(label)
TextView.setValue(label, forKey: "_placeholderLabel")