Skip to content

Instantly share code, notes, and snippets.

@3lvis
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3lvis/8369592963b62b19f33b to your computer and use it in GitHub Desktop.
Save 3lvis/8369592963b62b19f33b to your computer and use it in GitHub Desktop.
Who said that XML was a good writing to write visual interfaces?

How is this

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="ufC-wZ-h7g">
            <objects>
                <viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="circle" customModuleProvider="target" sceneMemberID="viewController">
                    <layoutGuides>
                        <viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
                        <viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
                    </layoutGuides>
                    <view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
                        <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
                        <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                        <subviews>
                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="eYi-JD-mWg">
                                <rect key="frame" x="275" y="275" width="50" height="50"/>
                                <color key="backgroundColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                                <constraints>
                                    <constraint firstAttribute="width" constant="50" id="9Tr-nG-cw8"/>
                                    <constraint firstAttribute="height" constant="50" id="EkH-Hj-yUz"/>
                                </constraints>
                            </view>
                        </subviews>
                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
                        <constraints>
                            <constraint firstAttribute="centerX" secondItem="eYi-JD-mWg" secondAttribute="centerX" id="Bmj-a1-lRf"/>
                            <constraint firstAttribute="centerY" secondItem="eYi-JD-mWg" secondAttribute="centerY" id="Cda-CH-TVQ"/>
                            <constraint firstAttribute="centerY" secondItem="eYi-JD-mWg" secondAttribute="centerY" id="fuY-1Q-DUr"/>
                            <constraint firstAttribute="centerX" secondItem="eYi-JD-mWg" secondAttribute="centerX" id="v2a-Gv-Wys"/>
                        </constraints>
                    </view>
                    <connections>
                        <outlet property="circle" destination="eYi-JD-mWg" id="Hrt-YQ-hmA"/>
                    </connections>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
            </objects>
        </scene>
    </scenes>
</document>

This is needed too:

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var circle: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        circle.layer.cornerRadius = 25.0
    }
}

Better than this

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let circle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 50.0, height: 50.0))
        circle.center = view.center
        circle.layer.cornerRadius = 25.0
        circle.backgroundColor = .redColor()

        view.addSubview(circle);
    }
}

The output is the same, a centerd circular view with a radius of 25.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment