Skip to content

Instantly share code, notes, and snippets.

View muhlenXi's full-sized avatar
🎯
Focusing

YinjunXi muhlenXi

🎯
Focusing
View GitHub Profile
@muhlenXi
muhlenXi / typedef.c
Created August 8, 2020 09:33
typedef 和 typedef struct 的使用
#include <stdio.h>
// 给 int 类型起个别名为 INT
typedef int INT;
// 方式 2
// 定义 Student 结构体类型
struct Student {
char name;
int age;
@muhlenXi
muhlenXi / Mediator.m
Last active September 26, 2019 08:39
通过 NSInvocation 间接调用对象的方法
#import "Mediator.h"
NSString * const kMediatorParamsKeySwiftTargetModuleName = @"kMediatorParamsKeySwiftTargetModuleName";
@interface Mediator ()
@property (nonatomic, copy) NSMutableDictionary *cachedTarget;
@end
@muhlenXi
muhlenXi / decimalFormatter.swift
Last active April 13, 2019 08:04
金额分 数字格式化 如 4132 --> 4,132.00
/// 金额分 数字格式化 如 4132 --> 4,132.00
func decimalFormatterValue(value: Int) -> String? {
let decimal = value % 100
let nonDecimal = value / 100
let formatter = NumberFormatter.init()
formatter.numberStyle = .decimal
if let title = formatter.string(from: NSNumber.init(value: nonDecimal)) {
return title + String.init(format: ".%02d", decimal)
}
return nil
@muhlenXi
muhlenXi / CAShapeLayer.swift
Created March 8, 2019 09:12
绘制带弧度的视图
/// 带弧度的 View
public static func createCurveView(frame: CGRect, curveScale: CGFloat, fillColor: UIColor = UIColor.white) -> UIView {
let view = UIView(frame: frame)
view.backgroundColor = UIColor.clear
let finalSize = CGSize(width: UIScreen.main.bounds.size.width, height: frame.size.height)
let layer = CAShapeLayer()
let bezier = UIBezierPath()
bezier.move(to: CGPoint(x:0, y:0))
bezier.addLine(to: CGPoint(x:0, y:finalSize.height))
@muhlenXi
muhlenXi / Gradient.swift
Created March 8, 2019 09:09
给视图添加渐变效果
let contentView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 200))
let gradientLayer = CAGradientLayer()
gradientLayer.frame = self.bounds
gradientLayer.colors = [UIColor.white.withAlphaComponent(0).cgColor, UIColor.white.cgColor]
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = CGPoint(x: 0, y: 0.5)
contentView.layer.addSublayer(gradientLayer)
@muhlenXi
muhlenXi / Biometrics.swift
Last active January 25, 2019 08:54
iOS 指纹或面部识别
import LocalAuthentication
@objc func onClickPayBtn(_ sender: UIButton) {
let context = LAContext()
var error: NSError?
let isEnable = context.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: &error)
if isEnable == false {
if let err = error {
var message = ""
switch err.code {
@muhlenXi
muhlenXi / FontViewController.swift
Created December 2, 2018 09:42
一个 tableView 显示、编辑、删除的 demo
//
// FontViewController.swift
// SF
//
// Created by muhlenXi on 2018/12/2.
// Copyright © 2018 muhlenXi. All rights reserved.
//
import UIKit
@muhlenXi
muhlenXi / AreaSelectPicker.swift
Created December 2, 2018 08:53
一个简单收货地址选择器的demo
//
// AreaSelectPicker.swift
// SF
//
// Created by muhlenXi on 2018/11/28.
// Copyright © 2018 muhlenXi. All rights reserved.
//
import UIKit
@muhlenXi
muhlenXi / collectionView.swift
Last active December 2, 2018 03:23
UICollectionView 的应用 demo
import UIKit
fileprivate let CellIdentifier = "CellIdentifier"
// MARK: InterCell
class InterCell: UICollectionViewCell {
lazy var thumbnail: UIImageView = {
let imageView = UIImageView()
imageView.backgroundColor = UIColor.white
@muhlenXi
muhlenXi / URL.swift
Created November 23, 2018 05:55
URL 参数的处理
import Foundation
public extension URL {
/// 获取 URL 参数和值
public var queryParameters: [String: String]? {
guard let components = URLComponents(url: self, resolvingAgainstBaseURL: true), let queryItems = components.queryItems else {
return nil
}
var parameters = [String: String]()