Skip to content

Instantly share code, notes, and snippets.

View SwiftSIQI's full-sized avatar

SwiftSIQI SwiftSIQI

View GitHub Profile
@SwiftSIQI
SwiftSIQI / thirty-days-of-metal.md
Created November 26, 2023 12:36 — forked from ole/thirty-days-of-metal.md
Warren Moore – Thirty Days of Metal
+ (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...
})
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state {
[self setBackgroundImage:[UIButton imageWithColor:backgroundColor] forState:state];
}
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
@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();