Skip to content

Instantly share code, notes, and snippets.

View daoseng33's full-sized avatar
💭
una yaha

Rayray daoseng33

💭
una yaha
View GitHub Profile
// Set up the shape of the circle
CAShapeLayer *border = [CAShapeLayer layer];
border.path = [UIBezierPath bezierPathWithRoundedRect:self.myImageView.frame cornerRadius:self.myImageView.frame.size.height/2].CGPath;
border.anchorPoint = CGPointMake(0.5, 0.5);
border.position= CGPointMake(self.myImageView.bounds.origin.x, self.myImageView.bounds.origin.y);
border.fillColor = [UIColor clearColor].CGColor;
border.strokeColor = [UIColor blueColor].CGColor;
border.lineWidth = 5; [self.view.layer addSublayer:border];
// Configure animation
// draw Border
if let userDict = User.convertToDict() {
// Do something you want with dict
}
struct User: Convertable {
let name: String
let phone: String
}
import Foundation
protocol Convertable: Codable {
}
// Convert struct to dictionary
extension Convertable {
func convertToDict() -> Dictionary<String, Any>? {
var dict: Dictionary<String, Any>? = nil
@daoseng33
daoseng33 / StopJumpingTableViewOnInsertRows.swift
Created July 11, 2018 12:31 — forked from joshdholtz/StopJumpingTableViewOnInsertRows.swift
Used when loading more data into UITableView for a smooth "infinite scroll" feel
// I dont want my table jumping/animation when appending new rows
// for an infinite scroll feel
//
// Some of this might not be needed but it works
//
// TODO: Possibly garbage
extension UITableView {
func reloadDataSmoothly() {
UIView.setAnimationsEnabled(false)
enum Type: String {
// 直接指定 API 回傳的 String
case regular = "regular"
case system = "system"
case advertise = "advertise"
var image: UIImage? {
// 一行搞定
return UIImage(named: self.rawValue)
}
let json = ["type": 1]
if let typeNumber = json["type"] {
imageView.image = Type(rawValue: typeNumber)?.image
}
enum Type: Int {
case regular = 0
case system
case advertise
var image: UIImage? {
switch self {
case .regular:
return UIImage(named: "regular")
case .system:
enum Type {
case regular
case system
case advertise
var image: UIImage? {
switch self {
case .regular:
return UIImage(named: "regular")
case .system:
@daoseng33
daoseng33 / type.swift
Last active June 28, 2018 12:46
Enum type
enum Type {
case regular
case system
case advertise
}