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
// | |
// UIView+LayoutAnchors.swift | |
// | |
// Created by Vinay Jain. | |
// | |
import UIKit | |
protocol LayoutAnchor { | |
func constraint(equalTo anchor: Self, |
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
text = "This could be a single line text but its too long to fit in one." | |
lines = text_wrap(text, font, image_size[0]) | |
line_height = font.getsize('hg')[1] | |
x = 10 | |
y = 20 | |
for line in lines: | |
# draw the line on the image | |
draw.text((x, y), line, fill=color, font=font) | |
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
text = "This could be a single line text but it can't fit in one line." | |
lines = text_wrap(lines, font) | |
line_height = font.get_size('hg')[1] | |
print line_height | |
# Output | |
# 62 |
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
text = "This could be a single line text but it can't fit in one line." | |
lines = text_wrap(lines, font) | |
for line in lines: | |
print font.getsize(line)[1] | |
# Output | |
# 62 | |
# 51 |
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
from PIL import Image | |
from PIL import ImageFont | |
from PIL import ImageDraw | |
def text_wrap(text, font, max_width): | |
lines = [] | |
# If the width of the text is smaller than image width | |
# we don't need to split it, just add it to the lines array | |
# and return | |
if font.getsize(text)[0] <= max_width: |
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
# create font object with the font file and specify | |
# desired size | |
font = ImageFont.truetype('Roboto-Bold.ttf', size=45) | |
# starting position of the message | |
(x, y) = (50, 50) | |
message = "Happy Birthday!" | |
color = 'rgb(0, 0, 0)' # black color |
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 required classes | |
from PIL import Image, ImageDraw, ImageFont | |
# create Image object with the input image | |
image = Image.open('background.png') | |
# initialise the drawing context with | |
# the image object as background | |
draw = ImageDraw.Draw(image) |
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
setAnchorPoint(CGPoint(x: 0.5, y: 0.5), forLayer: layer) | |
private func setAnchorPoint(anchorPoint: CGPoint, forLayer layer: CALayer) { | |
var newPoint = CGPoint(x: layer.bounds.size.width * anchorPoint.x, y: layer.bounds.size.height * anchorPoint.y) | |
var oldPoint = CGPoint(x: layer.bounds.size.width * layer.anchorPoint.x, y: layer.bounds.size.height * layer.anchorPoint.y) | |
newPoint = CGPointApplyAffineTransform(newPoint, layer.affineTransform()) | |
oldPoint = CGPointApplyAffineTransform(oldPoint, layer.affineTransform()) | |
var position = layer.position | |
position.x -= oldPoint.x |
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
- (IBAction)applyItalicAttributes:(UIButton *)sender { | |
NSDictionary *attributes = @{ | |
NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Italic" | |
size:30.0] | |
}; | |
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"HelveticaNeue with Italic Attributes" | |
attributes:attributes]; | |
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
###################### | |
# Options | |
###################### | |
REVEAL_ARCHIVE_IN_FINDER=false | |
FRAMEWORK_NAME="${PROJECT_NAME}" | |
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework" |