This file contains hidden or 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
| // Swift 3 | |
| func Delay(seconds: TimeInterval, _ completion: @escaping () -> Void) { | |
| let when = DispatchTime.now() + seconds | |
| DispatchQueue.main.asyncAfter(deadline: when) { | |
| completion() | |
| } | |
| } |
This file contains hidden or 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
| class TimeOut: NSObject { | |
| private let queue:dispatch_queue_t | |
| private let semaphore:dispatch_semaphore_t | |
| var completion:()->() | |
| convenience init(_ seconds:Double, completion:()->()) { | |
| self.init(seconds, fireOn:dispatch_get_main_queue(), completion:completion) | |
| } | |
This file contains hidden or 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 SystemConfiguration | |
| public class Reachability { | |
| class func isConnectedToNetwork() -> Bool { | |
| var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0)) | |
| zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress)) | |
| zeroAddress.sin_family = sa_family_t(AF_INET) | |
| let defaultRouteReachability = withUnsafePointer(&zeroAddress) { | |
| SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, UnsafePointer($0)) |
This file contains hidden or 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
| let myView = MyView(title: "Title", subTitle: "Sub title", content: "Content") | |
| let myView2 = MyView(frame: .zero) | |
| myView2.setTitle("Title", subTitle: "Sub title", content: "Content") |
This file contains hidden or 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 UIKit | |
| import SnapKit | |
| class MyView: UIView { | |
| private var _titleLabel: UILabel! | |
| private var _subTitleLabel: UILabel! | |
| private var _contentLabel: UILabel! | |
| init(title: String? = nil, subTitle: String? = nil, content: String? = nil) { |
This file contains hidden or 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
| myView = MyView(title: "Lorem Ipsum is simply dummy text of the printing", subTitle: "Lorem Ipsum is simply dummy text of the printing", content: "Lorem Ipsum is simply dummy text of the printing") | |
| self.view.addSubview(myView) | |
| myView.snp.makeConstraints { (make) in | |
| make.width.equalToSuperview().multipliedBy(0.5) | |
| make.centerX.centerY.equalToSuperview() | |
| } |
This file contains hidden or 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
| private func setupComponents() { | |
| _titleLabel = UILabel(frame: .zero) | |
| _titleLabel.textColor = UIColor.black | |
| _titleLabel.numberOfLines = 0 | |
| _titleLabel.backgroundColor = UIColor.red | |
| addSubview(_titleLabel) | |
| _subTitleLabel = UILabel(frame: .zero) | |
| _subTitleLabel.textColor = UIColor.black | |
| _subTitleLabel.numberOfLines = 0 |
This file contains hidden or 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
| public func setTitle(_ title: String? = nil, subTitle: String? = nil, content: String? = nil) { | |
| _titleLabel.text = title | |
| _subTitleLabel.text = subTitle | |
| _contentLabel.text = content | |
| updateFrame() | |
| } | |
| private func updateFrame() { | |
| let titleLabelSize = _titleLabel.sizeThatFits(CGSize(width: _titleLabel.frame.width, height: 9999)) |
This file contains hidden or 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
| struct ContentView: View { | |
| @State var scale: CGFloat = 0 | |
| @State var showingBlankHeart = true | |
| @State var heartScale: CGFloat = 0 | |
| @State var textOpacity: Double = 1 | |
| @State var offset1: CGFloat = 0 | |
| @State var plus1Opacity: Double = 1 | |
| @State var offset2: CGFloat = 0 | |
| @State var plus2Opacity: Double = 1 |
This file contains hidden or 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
| struct ContentView: View { | |
| @State private var isActive = false | |
| @State private var isPressing = false | |
| @State var scale: CGFloat = 1 | |
| @State var count = 0 | |
| var body: some View { | |
| ZStack { | |
| Circle() |
OlderNewer