Created
November 27, 2014 13:31
-
-
Save tdksk/22ab94687e4a8103edc2 to your computer and use it in GitHub Desktop.
Swift Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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