createView: function(args) { ENSURE_ARG_COUNT(args, 1); var view = new UIView(); view.setFrame(UIScreen.mainScreen().bounds); view.setBackgroundColor(UIColor.redColor()); return view; }
view.onDrawRect = function(rect) { // this function is called when the drawRect: is invoked to render the view var beams = 9; var radius = rect.size.width / 2; UIColor.whiteColor().setFill(); CGContextFillRect(UIGraphicsGetCurrentContext(), rect); UIColor.redColor().setFill(); UIColor.greenColor().setStroke(); var bezierPath = UIBezierPath.bezierPath(); var centerPoint = CGPointMake(rect.size.width / 2, rect.size.height / 2); var thisPoint = CGPointMake(centerPoint.x + radius, centerPoint.y); bezierPath.moveToPoint(centerPoint); var thisAngle = 0; var sliceDegrees = 360 / beams / 2; for (var i = 0; i < beams; i++) { var x = radius * Math.cos(DEGREES_TO_RADIANS(thisAngle + sliceDegrees)) + centerPoint.x; var y = radius * Math.sin(DEGREES_TO_RADIANS(thisAngle + sliceDegrees)) + centerPoint.y; thisPoint = CGPointMake(x, y); bezierPath.addLineToPoint(thisPoint); thisAngle += sliceDegrees; var x2 = radius * Math.cos(DEGREES_TO_RADIANS(thisAngle + sliceDegrees)) + centerPoint.x; var y2 = radius * Math.sin(DEGREES_TO_RADIANS(thisAngle + sliceDegrees)) + centerPoint.y; thisPoint = CGPointMake(x2, y2); bezierPath.addLineToPoint(thisPoint); bezierPath.addLineToPoint(centerPoint); thisAngle += sliceDegrees; } bezierPath.closePath(); bezierPath.lineWidth = 2; bezierPath.fill(); bezierPath.stroke(); }
function generateColorLookup() { var white = UIColor.whiteColor(); var black = UIColor.blackColor(); return { "black": black, "gray": UIColor.grayColor(), "darkgray": UIColor.darkGrayColor(), "lightgray": UIColor.lightGrayColor(), "white": white, "red": UIColor.redColor(), "green": UIColor.greenColor(), "blue": UIColor.blueColor(), "cyan": UIColor.cyanColor(), "yellow": UIColor.yellowColor(), "magenta": UIColor.magentaColor(), "orange": UIColor.orangeColor(), "purple": UIColor.purpleColor(), "brown": UIColor.brownColor(), "transparent": UIColor.clearColor(), "stripped": UIColor.groupTableViewBackgroundColor(), "aqua": colorForHex("0ff"), "fuchsia": colorForHex("f0f"), "lime": colorForHex("0f0"), "maroon": colorForHex("800"), "pink": colorForHex("FFC0CB"), "navy": colorForHex("000080"), "silver": colorForHex("c0c0c0"), "olive": colorForHex("808000"), "teal": colorForHex("008080"), "fff": white, "ffff": white, "ffffff": white, "ffffffff": white, "000": black, "0000": black, "000000": black, "00000000": black, }; };
(function (container) { var UILabel = require('UIKit/UILabel'), UIColor = require('UIKit/UIColor'), UIScreen = require('UIKit/UIScreen'), UIView = require('UIKit/UIView'), CGRectMake = require('CoreGraphics/CoreGraphics').CGRectMake, UIKit = require('UIKit/UIKit'), NSLayoutConstraint = require('UIKit/NSLayoutConstraint'); var label = new UILabel(); label.translatesAutoresizingMaskIntoConstraints = false; label.setText('Hello World'); label.setTextAlignment(UIKit.NSTextAlignmentCenter); label.setTextColor(UIColor.redColor()); label.setBackgroundColor(UIColor.blueColor()); var view = new UIView(); view.setBackgroundColor(UIColor.yellowColor()); view.addSubview(label); var heightConstraint = NSLayoutConstraint.constraintWithItemAttributeRelatedByToItemAttributeMultiplierConstant( label, UIKit.NSLayoutAttributeHeight, UIKit.NSLayoutRelationEqual, null, UIKit.NSLayoutAttributeNotAnAttribute, 1, 100 ); var widthConstraint = NSLayoutConstraint.constraintWithItemAttributeRelatedByToItemAttributeMultiplierConstant( label, UIKit.NSLayoutAttributeWidth, UIKit.NSLayoutRelationEqual, null, UIKit.NSLayoutAttributeNotAnAttribute, 1, 200 ); var horizontalConstraint = NSLayoutConstraint.constraintWithItemAttributeRelatedByToItemAttributeMultiplierConstant( label, UIKit.NSLayoutAttributeCenterX, UIKit.NSLayoutRelationEqual, view, UIKit.NSLayoutAttributeCenterX, 1, 0 ); var verticalConstraint = NSLayoutConstraint.constraintWithItemAttributeRelatedByToItemAttributeMultiplierConstant( label, UIKit.NSLayoutAttributeCenterY, UIKit.NSLayoutRelationEqual, view, UIKit.NSLayoutAttributeCenterY, 1, 0 ); label.addConstraint(heightConstraint); label.addConstraint(widthConstraint); view.addConstraint(horizontalConstraint); view.addConstraint(verticalConstraint); container.add(view); })($.autolayout_container);