Great series of short articles introducing Apple's Metal framework.
- 2022-04-01: Day 1: Devices
- 2022-04-02: Day 2: Buffers
- 2022-04-03: Day 3: Commands
- 2022-04-04: Day 4: MTKView
- 2022-04-05: Day 5: Shaders
- 2022-04-06: Day 6: Pipelines
Great series of short articles introducing Apple's Metal framework.
| + (UIColor *)randomColor{ | |
| CGFloat r = arc4random_uniform(256)/255.0; | |
| CGFloat g = arc4random_uniform(256)/255.0; | |
| CGFloat b = arc4random_uniform(256)/255.0; | |
| return [UIColor colorWithRed:r green:g blue:b alpha:1]; | |
| } |
| class func randomColor() -> UIColor { | |
| let red = CGFloat(arc4random_uniform(255))/CGFloat(255.0) | |
| let green = CGFloat( arc4random_uniform(255))/CGFloat(255.0) | |
| let blue = CGFloat(arc4random_uniform(255))/CGFloat(255.0) | |
| return UIColor(red: red, green: green, blue: blue, alpha: 1) | |
| } |
| // Horizontal Constraints | |
| myView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true | |
| // Vertical constraints | |
| myView.bottomAnchor.constraint(equalTo: view.topAnchor, constant: 8).isActive=true | |
| // Size-Based Constraints | |
| myView.widthAnchor.constraint(equalToConstant: 50.0).isActive = true | |
| myView.heightAnchor.constraint(equalTo:otherView.heightAnchor, multiplier: 2.0).isActive = true |
| let time: NSTimeInterval = XXX | |
| let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(time * Double(NSEC_PER_SEC))) | |
| dispatch_after(delay, dispatch_get_main_queue(), { | |
| //anythiny you want... | |
| }) |
| @implementation UIImage (Additions) | |
| - (UIImage *)makeCircularImageWithSize:(CGSize)size withBorderWidth:(CGFloat)width | |
| { | |
| // make a CGRect with the image's size | |
| CGRect circleRect = (CGRect) {CGPointZero, size}; | |
| // begin the image context since we're not in a drawRect: | |
| UIGraphicsBeginImageContextWithOptions(circleRect.size, NO, 0); | |
| - (UIImage *)antiAlias | |
| { | |
| CGFloat border = 1.0f; | |
| CGRect rect = CGRectMake(border, border, self.size.width-2*border, self.size.height-2*border); | |
| UIImage *img = nil; | |
| UIGraphicsBeginImageContext(CGSizeMake(rect.size.width,rect.size.height)); | |
| [self drawInRect:CGRectMake(-1, -1, self.size.width, self.size.height)]; | |
| img = UIGraphicsGetImageFromCurrentImageContext(); |