|
| 1 | +// |
| 2 | +// UIViewAdditions.m |
| 3 | +// PAR Works iOS SDK |
| 4 | +// |
| 5 | +// Copyright 2013 PAR Works, Inc. |
| 6 | +// |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// Unless required by applicable law or agreed to in writing, software |
| 14 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +// See the License for the specific language governing permissions and |
| 17 | +// limitations under the License. |
| 18 | +// |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +#import "UIView+FrameAdditions.h" |
| 23 | + |
| 24 | +@implementation UIView (FrameAdditions) |
| 25 | + |
| 26 | +- (void)setFrameY:(float)y |
| 27 | +{ |
| 28 | + CGRect frame = [self frame]; |
| 29 | + frame.origin.y = y; |
| 30 | + [self setFrame: frame]; |
| 31 | +} |
| 32 | + |
| 33 | +- (void)setFrameX:(float)x |
| 34 | +{ |
| 35 | + CGRect frame = [self frame]; |
| 36 | + frame.origin.x = x; |
| 37 | + [self setFrame: frame]; |
| 38 | +} |
| 39 | + |
| 40 | +- (void)shiftFrame:(CGPoint)offset |
| 41 | +{ |
| 42 | + CGRect frame = [self frame]; |
| 43 | + [self setFrame: CGRectMake(frame.origin.x + offset.x, frame.origin.y + offset.y, frame.size.width, frame.size.height)]; |
| 44 | +} |
| 45 | + |
| 46 | +- (void)shiftFrameUsingTransform:(CGPoint)offset |
| 47 | +{ |
| 48 | + CGAffineTransform t = [self transform]; |
| 49 | + t = CGAffineTransformTranslate(t,offset.x, offset.y); |
| 50 | + [self setTransform: t]; |
| 51 | +} |
| 52 | + |
| 53 | +- (void)setFrameOrigin:(CGPoint)origin |
| 54 | +{ |
| 55 | + CGRect frame = [self frame]; |
| 56 | + [self setFrame: CGRectMake(origin.x, origin.y, frame.size.width, frame.size.height)]; |
| 57 | +} |
| 58 | + |
| 59 | +- (void)setFrameSize:(CGSize)size |
| 60 | +{ |
| 61 | + CGRect frame = [self frame]; |
| 62 | + [self setFrame: CGRectMake(frame.origin.x, frame.origin.y, size.width, size.height)]; |
| 63 | +} |
| 64 | + |
| 65 | +- (void)setFrameCenter:(CGPoint)p |
| 66 | +{ |
| 67 | + CGRect frame = [self frame]; |
| 68 | + [self setFrame: CGRectMake(p.x - frame.size.width / 2, p.y - frame.size.height / 2, frame.size.width, frame.size.height)]; |
| 69 | +} |
| 70 | + |
| 71 | +- (void)setFrameWidth:(float)w |
| 72 | +{ |
| 73 | + CGRect frame = [self frame]; |
| 74 | + frame.size.width = w; |
| 75 | + [self setFrame: frame]; |
| 76 | +} |
| 77 | + |
| 78 | +- (void)setFrameHeight:(float)h |
| 79 | +{ |
| 80 | + CGRect frame = [self frame]; |
| 81 | + frame.size.height = h; |
| 82 | + [self setFrame: frame]; |
| 83 | +} |
| 84 | + |
| 85 | +- (void)setFrameSizeAndRemainCentered:(CGSize)desired |
| 86 | +{ |
| 87 | + CGRect current = [self frame]; |
| 88 | + CGRect fixed = CGRectMake(current.origin.x - (desired.width - current.size.width) / 2, |
| 89 | + current.origin.y - (desired.height - current.size.height) / 2, desired.width, desired.height); |
| 90 | + |
| 91 | + [self setFrame: fixed]; |
| 92 | +} |
| 93 | + |
| 94 | +- (void)multiplyFrameBy:(float)t |
| 95 | +{ |
| 96 | + CGRect f = [self frame]; |
| 97 | + f.origin.x *= t; |
| 98 | + f.origin.y *= t; |
| 99 | + f.size.width *= t; |
| 100 | + f.size.height *= t; |
| 101 | + |
| 102 | + [self setFrame:f]; |
| 103 | +} |
| 104 | + |
| 105 | +- (CGPoint)topRight |
| 106 | +{ |
| 107 | + return CGPointMake([self frame].origin.x + [self frame].size.width, [self frame].origin.y); |
| 108 | +} |
| 109 | + |
| 110 | +- (CGPoint)bottomRight |
| 111 | +{ |
| 112 | + return CGPointMake([self frame].origin.x + [self frame].size.width, [self frame].origin.y + [self frame].size.height); |
| 113 | +} |
| 114 | + |
| 115 | +- (CGPoint)bottomLeft |
| 116 | +{ |
| 117 | + return CGPointMake([self frame].origin.x, [self frame].origin.y + [self frame].size.height); |
| 118 | +} |
| 119 | + |
| 120 | +@end |
0 commit comments