Skip to content

Instantly share code, notes, and snippets.

View milomai's full-sized avatar

Milo milomai

  • 深圳 Shenzhen
View GitHub Profile
@milomai
milomai / transparent_inside_mask.dart
Created December 30, 2020 10:01
Draw mask with hollow (transparent hole inside)
var maskColor = Colors.black.withOpacity(0.4);
ColorFiltered(
colorFilter: ColorFilter.mode(maskColor,
BlendMode.srcOut), // This mean: the child's opacity part will be transparent, but the transparent will render with maskColor
child: Container(
color: Colors.transparent,
child: Center( // Any shape you like, but make sure the widget is opacity
child: Container(
width: 200,
@milomai
milomai / map_list_with_index.dart
Last active December 30, 2020 09:37
[Dart] Map list with index
List<int> list = [1, 2, 3];
List<String> result = list.asMap().entries.map((entry) {
int idx = entry.key;
int val = entry.value;
return "$idx: $val";
}).toList();
// or
List<String> result = list
.asMap()
extension UIView {
func animateUpdateConstraints(duration: TimeInterval, animation: @escaping ()->Void) {
animation()
setNeedsUpdateConstraints()
Self.animate(withDuration: duration) {
self.layoutIfNeeded()
}
}
}
@milomai
milomai / UserDefaultKey.swift
Created August 7, 2020 09:15
Swift 访问 UserDefaults 便捷方法
import UIKit
enum UserDefaultKey: String {
case id
case token = "access_token" // special name
// Add your keys here
// ...
var prefix: String { "Milo" }
@milomai
milomai / VerticallyButton.swift
Created May 21, 2020 10:19
标题在图片下方的按钮
func centerVertically(padding: CGFloat = 6.0) {
guard
let imageViewSize = self.imageView?.frame.size,
let titleLabelSize = self.titleLabel?.frame.size else {
return
}
let totalHeight = imageViewSize.height + titleLabelSize.height + padding
self.imageEdgeInsets = UIEdgeInsets(
@milomai
milomai / export_uni_app_native_resoures.sh
Last active June 4, 2019 02:59
uni-app 生成原生 App 本地打包资源脚本
# 目前只支持 Mac OS X
# 需要先安装 HBuilderX,并且能够正常从 HBuilderX 界面中导出本地打包资源。
# 使用方法: sh export_uni_app_native_resoures.sh /path/to/uni_app_project
# 导出的资源在 /path/to/uni_app_project/unpackage/dist/build/app-plus
PROJECT_PATH=`realpath ${1}`
echo "工程路径: ${PROJECT_PATH}"
EXPORT_PATH="${PROJECT_PATH}/unpackage/dist/build/app-plus"
echo "导出到: ${EXPORT_PATH}"
@milomai
milomai / refreshAndLoadMore.m
Created August 4, 2018 07:50
UIScrollView 下拉刷新和上拉加载更多
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
// contentSize 高度小于 scrollView 控件的高度,说明内容不足一页,不需要加载更多
CGFloat offset = scrollView.contentSize.height-scrollView.height;
if (offset > 0 && scrollView.contentOffset.y > offset) {
// 加载更多
}
if (scrollView.contentOffset.y < 0) {
// 刷新
}