Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Swift Playground
import UIKit
// Line Height ----------------------------------------
let label = UILabel(frame: CGRectMake(0, 0, 300, 100))
label.numberOfLines = 0
label.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
label // Raw
let lineHeightMultiple: CGFloat = 1.5
let attributedString = label.attributedText.mutableCopy() as NSMutableAttributedString
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineHeightMultiple = lineHeightMultiple;
attributedString.addAttribute(
NSParagraphStyleAttributeName,
value: paragraphStyle,
range: NSMakeRange(0, attributedString.length))
label.attributedText = attributedString
label // Output
// Partial Corner Radius ----------------------------------------
let view = UIView(frame: CGRectMake(0, 0, 100, 30))
view.backgroundColor = UIColor.orangeColor()
view // Raw
let cornerRadius: CGFloat = 4.0
let corners = UIRectCorner.TopLeft | UIRectCorner.TopRight
view.layoutIfNeeded()
let maskPath = UIBezierPath(
roundedRect: view.bounds,
byRoundingCorners: corners,
cornerRadii: CGSizeMake(cornerRadius, cornerRadius))
let maskLayer = CAShapeLayer()
maskLayer.frame = view.bounds
maskLayer.path = maskPath.CGPath
view.layer.mask = maskLayer
view // Output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment