├── .gitignore ├── IQLabelView.podspec ├── IQLabelView ├── IQLabelView.bundle │ ├── sticker_close@2x.png │ └── sticker_resize@2x.png ├── IQLabelView.h ├── IQLabelView.m ├── UITextField+DynamicFontSize.h └── UITextField+DynamicFontSize.m ├── IQLabelViewDemo ├── IQLabelViewDemo.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── IQLabelViewDemo │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── image.imageset │ │ │ ├── 10808642_854802211228961_1051550445_n.jpg │ │ │ └── Contents.json │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ └── main.m └── IQLabelViewDemoTests │ ├── IQLabelViewDemoTests.m │ └── Info.plist ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | .DS_Store 20 | 21 | # CocoaPods 22 | # 23 | # We recommend against adding the Pods directory to your .gitignore. However 24 | # you should judge for yourself, the pros and cons are mentioned at: 25 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 26 | # 27 | # Pods/ 28 | -------------------------------------------------------------------------------- /IQLabelView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |spec| 2 | spec.name = "IQLabelView" 3 | spec.version = "0.2.1" 4 | spec.summary = "IQLabelView is used to add text overlay and resize and rotate it with single finger." 5 | 6 | spec.homepage = "https://github.com/kcandr/IQLabelView" 7 | 8 | spec.author = { "kcandr" => "romanchev.aleksandr@gmail.com" } 9 | spec.social_media_url = "http://twitter.com/kcandr_" 10 | spec.license = { :type => "MIT", :file => "LICENSE" } 11 | 12 | spec.source = { :git => "https://github.com/kcandr/IQLabelView.git", :tag => "0.2.1" } 13 | spec.source_files = "IQLabelView/*.{h,m}" 14 | spec.resource = "IQLabelView/IQLabelView.bundle" 15 | 16 | spec.platform = :ios, "7.0" 17 | spec.framework = "QuartzCore" 18 | spec.requires_arc = true 19 | 20 | end 21 | -------------------------------------------------------------------------------- /IQLabelView/IQLabelView.bundle/sticker_close@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcandr/IQLabelView/2fa7a1aaee68483c7b3991dd9b9d62ed89eab0d4/IQLabelView/IQLabelView.bundle/sticker_close@2x.png -------------------------------------------------------------------------------- /IQLabelView/IQLabelView.bundle/sticker_resize@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcandr/IQLabelView/2fa7a1aaee68483c7b3991dd9b9d62ed89eab0d4/IQLabelView/IQLabelView.bundle/sticker_resize@2x.png -------------------------------------------------------------------------------- /IQLabelView/IQLabelView.h: -------------------------------------------------------------------------------- 1 | // 2 | // IQLabelView.h 3 | // Created by kcandr on 17/12/14. 4 | 5 | #import 6 | 7 | @protocol IQLabelViewDelegate; 8 | 9 | @interface IQLabelView : UIView 10 | 11 | /** 12 | * Text color. 13 | * 14 | * Default: white color. 15 | */ 16 | @property (nonatomic, strong) UIColor *textColor; 17 | 18 | /** 19 | * Border stroke color. 20 | * 21 | * Default: red color. 22 | */ 23 | @property (nonatomic, strong) UIColor *borderColor; 24 | 25 | /** 26 | * Name of text field font. 27 | * 28 | * Default: current system font 29 | */ 30 | @property (nonatomic, copy) NSString *fontName; 31 | 32 | /** 33 | * Size of text field font. 34 | */ 35 | @property (nonatomic, assign) CGFloat fontSize; 36 | 37 | /** 38 | * Image for close button. 39 | * 40 | * Default: sticker_close.png from IQLabelView.bundle. 41 | */ 42 | @property (nonatomic, strong) UIImage *closeImage; 43 | 44 | /** 45 | * Image for rotation button. 46 | * 47 | * Default: sticker_resize.png from IQLabelView.bundle. 48 | */ 49 | @property (nonatomic, strong) UIImage *rotateImage; 50 | 51 | /** 52 | * Placeholder. 53 | * 54 | * Default: nil 55 | */ 56 | @property (nonatomic, copy) NSAttributedString *attributedPlaceholder; 57 | 58 | /* 59 | * Base delegate protocols. 60 | */ 61 | @property (nonatomic, weak) id delegate; 62 | 63 | /** 64 | * Shows content shadow. 65 | * 66 | * Default: YES. 67 | */ 68 | @property (nonatomic) BOOL showsContentShadow; 69 | 70 | /** 71 | * Shows close button. 72 | * 73 | * Default: YES. 74 | */ 75 | @property (nonatomic, getter=isEnableClose) BOOL enableClose; 76 | 77 | /** 78 | * Shows rotate/resize butoon. 79 | * 80 | * Default: YES. 81 | */ 82 | @property (nonatomic, getter=isEnableRotate) BOOL enableRotate; 83 | 84 | /** 85 | * Resticts movements in superview bounds. 86 | * 87 | * Default: NO. 88 | */ 89 | @property (nonatomic, getter=isEnableMoveRestriction) BOOL enableMoveRestriction; 90 | 91 | /** 92 | * Hides border and control buttons. 93 | */ 94 | - (void)hideEditingHandles; 95 | 96 | /** 97 | * Shows border and control buttons. 98 | */ 99 | - (void)showEditingHandles; 100 | 101 | /** Sets the text alpha. 102 | * 103 | * @param alpha A value of text transparency. 104 | */ 105 | - (void)setTextAlpha:(CGFloat)alpha; 106 | 107 | /** Returns text alpha. 108 | * 109 | * @return A value of text transparency. 110 | */ 111 | - (CGFloat)textAlpha; 112 | 113 | @end 114 | 115 | @protocol IQLabelViewDelegate 116 | 117 | @optional 118 | 119 | /** 120 | * Occurs when a touch gesture event occurs on close button. 121 | * 122 | * @param label A label object informing the delegate about action. 123 | */ 124 | - (void)labelViewDidClose:(IQLabelView *)label; 125 | 126 | /** 127 | * Occurs when border and control buttons was shown. 128 | * 129 | * @param label A label object informing the delegate about showing. 130 | */ 131 | - (void)labelViewDidShowEditingHandles:(IQLabelView *)label; 132 | 133 | /** 134 | * Occurs when border and control buttons was hidden. 135 | * 136 | * @param label A label object informing the delegate about hiding. 137 | */ 138 | - (void)labelViewDidHideEditingHandles:(IQLabelView *)label; 139 | 140 | /** 141 | * Occurs when label become first responder. 142 | * 143 | * @param label A label object informing the delegate about action. 144 | */ 145 | - (void)labelViewDidStartEditing:(IQLabelView *)label; 146 | 147 | /** 148 | * Occurs when label starts move or rotate. 149 | * 150 | * @param label A label object informing the delegate about action. 151 | */ 152 | - (void)labelViewDidBeginEditing:(IQLabelView *)label; 153 | 154 | /** 155 | * Occurs when label continues move or rotate. 156 | * 157 | * @param label A label object informing the delegate about action. 158 | */ 159 | - (void)labelViewDidChangeEditing:(IQLabelView *)label; 160 | 161 | /** 162 | * Occurs when label ends move or rotate. 163 | * 164 | * @param label A label object informing the delegate about action. 165 | */ 166 | - (void)labelViewDidEndEditing:(IQLabelView *)label; 167 | 168 | @end 169 | 170 | 171 | -------------------------------------------------------------------------------- /IQLabelView/IQLabelView.m: -------------------------------------------------------------------------------- 1 | // 2 | // IQLabelView.m 3 | // Created by kcandr on 17/12/14. 4 | 5 | #import "IQLabelView.h" 6 | #import 7 | #import "UITextField+DynamicFontSize.h" 8 | 9 | CG_INLINE CGPoint CGRectGetCenter(CGRect rect) 10 | { 11 | return CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); 12 | } 13 | 14 | CG_INLINE CGRect CGRectScale(CGRect rect, CGFloat wScale, CGFloat hScale) 15 | { 16 | return CGRectMake(rect.origin.x * wScale, rect.origin.y * hScale, rect.size.width * wScale, rect.size.height * hScale); 17 | } 18 | 19 | CG_INLINE CGFloat CGPointGetDistance(CGPoint point1, CGPoint point2) 20 | { 21 | CGFloat fx = (point2.x - point1.x); 22 | CGFloat fy = (point2.y - point1.y); 23 | 24 | return sqrt((fx*fx + fy*fy)); 25 | } 26 | 27 | CG_INLINE CGFloat CGAffineTransformGetAngle(CGAffineTransform t) 28 | { 29 | return atan2(t.b, t.a); 30 | } 31 | 32 | 33 | CG_INLINE CGSize CGAffineTransformGetScale(CGAffineTransform t) 34 | { 35 | return CGSizeMake(sqrt(t.a * t.a + t.c * t.c), sqrt(t.b * t.b + t.d * t.d)) ; 36 | } 37 | 38 | static IQLabelView *lastTouchedView; 39 | 40 | @interface IQLabelView () 41 | 42 | @end 43 | 44 | @implementation IQLabelView 45 | { 46 | CGFloat globalInset; 47 | 48 | CGRect initialBounds; 49 | CGFloat initialDistance; 50 | 51 | CGPoint beginningPoint; 52 | CGPoint beginningCenter; 53 | 54 | CGPoint touchLocation; 55 | 56 | CGFloat deltaAngle; 57 | CGRect beginBounds; 58 | 59 | CAShapeLayer *border; 60 | UITextField *labelTextField; 61 | UIImageView *rotateView; 62 | UIImageView *closeView; 63 | 64 | BOOL isShowingEditingHandles; 65 | } 66 | 67 | @synthesize textColor, borderColor; 68 | @synthesize fontName, fontSize; 69 | @synthesize enableClose, enableRotate, enableMoveRestriction, showsContentShadow; 70 | @synthesize delegate; 71 | @synthesize closeImage, rotateImage; 72 | 73 | - (void)refresh 74 | { 75 | if (self.superview) { 76 | CGSize scale = CGAffineTransformGetScale(self.superview.transform); 77 | CGAffineTransform t = CGAffineTransformMakeScale(scale.width, scale.height); 78 | [closeView setTransform:CGAffineTransformInvert(t)]; 79 | [rotateView setTransform:CGAffineTransformInvert(t)]; 80 | 81 | if (isShowingEditingHandles) { 82 | [labelTextField.layer addSublayer:border]; 83 | } else { 84 | [border removeFromSuperlayer]; 85 | } 86 | } 87 | } 88 | 89 | -(void)didMoveToSuperview 90 | { 91 | [super didMoveToSuperview]; 92 | [self refresh]; 93 | } 94 | 95 | - (void)setFrame:(CGRect)newFrame 96 | { 97 | [super setFrame:newFrame]; 98 | [self refresh]; 99 | } 100 | 101 | - (id)initWithFrame:(CGRect)frame 102 | { 103 | if (frame.size.width < 25) frame.size.width = 25; 104 | if (frame.size.height < 25) frame.size.height = 25; 105 | 106 | self = [super initWithFrame:frame]; 107 | if (self) { 108 | globalInset = 12; 109 | 110 | self.backgroundColor = [UIColor clearColor]; 111 | [self setAutoresizingMask:(UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth)]; 112 | borderColor = [UIColor redColor]; 113 | 114 | labelTextField = [[UITextField alloc] initWithFrame:CGRectInset(self.bounds, globalInset, globalInset)]; 115 | [labelTextField setAutoresizingMask:(UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight)]; 116 | [labelTextField setClipsToBounds:YES]; 117 | labelTextField.delegate = self; 118 | labelTextField.backgroundColor = [UIColor clearColor]; 119 | labelTextField.tintColor = [UIColor redColor]; 120 | labelTextField.textColor = [UIColor whiteColor]; 121 | labelTextField.text = @""; 122 | 123 | border = [CAShapeLayer layer]; 124 | border.strokeColor = borderColor.CGColor; 125 | border.fillColor = nil; 126 | border.lineDashPattern = @[@4, @3]; 127 | 128 | [self insertSubview:labelTextField atIndex:0]; 129 | 130 | closeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, globalInset * 2, globalInset * 2)]; 131 | [closeView setAutoresizingMask:(UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin)]; 132 | closeView.backgroundColor = [UIColor whiteColor]; 133 | closeView.layer.cornerRadius = globalInset - 5; 134 | closeView.userInteractionEnabled = YES; 135 | [self addSubview:closeView]; 136 | 137 | rotateView = [[UIImageView alloc] initWithFrame:CGRectMake(self.bounds.size.width-globalInset*2, self.bounds.size.height-globalInset*2, globalInset*2, globalInset*2)]; 138 | [rotateView setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin)]; 139 | rotateView.backgroundColor = [UIColor whiteColor]; 140 | rotateView.layer.cornerRadius = globalInset - 5; 141 | rotateView.contentMode = UIViewContentModeCenter; 142 | rotateView.userInteractionEnabled = YES; 143 | [self addSubview:rotateView]; 144 | 145 | UIPanGestureRecognizer *moveGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveGesture:)]; 146 | [self addGestureRecognizer:moveGesture]; 147 | 148 | UITapGestureRecognizer *singleTapShowHide = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(contentTapped:)]; 149 | [self addGestureRecognizer:singleTapShowHide]; 150 | 151 | UITapGestureRecognizer *closeTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeTap:)]; 152 | [closeView addGestureRecognizer:closeTap]; 153 | 154 | UIPanGestureRecognizer *panRotateGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(rotateViewPanGesture:)]; 155 | [rotateView addGestureRecognizer:panRotateGesture]; 156 | 157 | [moveGesture requireGestureRecognizerToFail:closeTap]; 158 | 159 | [self setEnableMoveRestriction:NO]; 160 | [self setEnableClose:YES]; 161 | [self setEnableRotate:YES]; 162 | [self setShowsContentShadow:YES]; 163 | [self setCloseImage:[UIImage imageNamed:@"IQLabelView.bundle/sticker_close.png"]]; 164 | [self setRotateImage:[UIImage imageNamed:@"IQLabelView.bundle/sticker_resize.png"]]; 165 | 166 | [self showEditingHandles]; 167 | [labelTextField becomeFirstResponder]; 168 | } 169 | return self; 170 | } 171 | 172 | - (void)layoutSubviews 173 | { 174 | if (labelTextField) { 175 | border.path = [UIBezierPath bezierPathWithRect:labelTextField.bounds].CGPath; 176 | border.frame = labelTextField.bounds; 177 | } 178 | } 179 | 180 | #pragma mark - Set Control Buttons 181 | 182 | - (void)setEnableClose:(BOOL)value 183 | { 184 | enableClose = value; 185 | [closeView setHidden:!enableClose]; 186 | [closeView setUserInteractionEnabled:enableClose]; 187 | } 188 | 189 | - (void)setEnableRotate:(BOOL)value 190 | { 191 | enableRotate = value; 192 | [rotateView setHidden:!enableRotate]; 193 | [rotateView setUserInteractionEnabled:enableRotate]; 194 | } 195 | 196 | - (void)setShowsContentShadow:(BOOL)showShadow 197 | { 198 | showsContentShadow = showShadow; 199 | 200 | if (showsContentShadow) { 201 | [self.layer setShadowColor:[UIColor blackColor].CGColor]; 202 | [self.layer setShadowOffset:CGSizeMake(0, 5)]; 203 | [self.layer setShadowOpacity:1.0]; 204 | [self.layer setShadowRadius:4.0]; 205 | } else { 206 | [self.layer setShadowColor:[UIColor clearColor].CGColor]; 207 | [self.layer setShadowOffset:CGSizeZero]; 208 | [self.layer setShadowOpacity:0.0]; 209 | [self.layer setShadowRadius:0.0]; 210 | } 211 | } 212 | 213 | - (void)setCloseImage:(UIImage *)image 214 | { 215 | closeImage = image; 216 | [closeView setImage:closeImage]; 217 | } 218 | 219 | - (void)setRotateImage:(UIImage *)image 220 | { 221 | rotateImage = image; 222 | [rotateView setImage:rotateImage]; 223 | } 224 | 225 | #pragma mark - Set Text Field 226 | 227 | - (void)setFontName:(NSString *)name 228 | { 229 | fontName = name; 230 | labelTextField.font = [UIFont fontWithName:fontName size:fontSize]; 231 | [labelTextField adjustsWidthToFillItsContents]; 232 | } 233 | 234 | - (void)setFontSize:(CGFloat)size 235 | { 236 | fontSize = size; 237 | labelTextField.font = [UIFont fontWithName:fontName size:fontSize]; 238 | } 239 | 240 | - (void)setTextColor:(UIColor *)color 241 | { 242 | textColor = color; 243 | labelTextField.textColor = textColor; 244 | } 245 | 246 | - (void)setBorderColor:(UIColor *)color 247 | { 248 | borderColor = color; 249 | border.strokeColor = borderColor.CGColor; 250 | } 251 | 252 | - (void)setTextAlpha:(CGFloat)alpha 253 | { 254 | labelTextField.alpha = alpha; 255 | } 256 | 257 | - (CGFloat)textAlpha 258 | { 259 | return labelTextField.alpha; 260 | } 261 | 262 | - (void)setAttributedPlaceholder:(NSAttributedString *)attributedPlaceholder 263 | { 264 | _attributedPlaceholder = attributedPlaceholder; 265 | [labelTextField setAttributedPlaceholder:attributedPlaceholder]; 266 | [labelTextField adjustsWidthToFillItsContents]; 267 | } 268 | 269 | #pragma mark - Bounds 270 | 271 | - (void)hideEditingHandles 272 | { 273 | lastTouchedView = nil; 274 | 275 | isShowingEditingHandles = NO; 276 | 277 | if (enableClose) closeView.hidden = YES; 278 | if (enableRotate) rotateView.hidden = YES; 279 | 280 | [labelTextField resignFirstResponder]; 281 | 282 | [self refresh]; 283 | 284 | if([delegate respondsToSelector:@selector(labelViewDidHideEditingHandles:)]) { 285 | [delegate labelViewDidHideEditingHandles:self]; 286 | } 287 | } 288 | 289 | - (void)showEditingHandles 290 | { 291 | [lastTouchedView hideEditingHandles]; 292 | 293 | isShowingEditingHandles = YES; 294 | 295 | lastTouchedView = self; 296 | 297 | if (enableClose) closeView.hidden = NO; 298 | if (enableRotate) rotateView.hidden = NO; 299 | 300 | [self refresh]; 301 | 302 | if([delegate respondsToSelector:@selector(labelViewDidShowEditingHandles:)]) { 303 | [delegate labelViewDidShowEditingHandles:self]; 304 | } 305 | } 306 | 307 | #pragma mark - Gestures 308 | 309 | - (void)contentTapped:(UITapGestureRecognizer*)tapGesture 310 | { 311 | if (isShowingEditingHandles) { 312 | [self hideEditingHandles]; 313 | [self.superview bringSubviewToFront:self]; 314 | } else { 315 | [self showEditingHandles]; 316 | } 317 | } 318 | 319 | - (void)closeTap:(UITapGestureRecognizer *)recognizer 320 | { 321 | [self removeFromSuperview]; 322 | 323 | if([delegate respondsToSelector:@selector(labelViewDidClose:)]) { 324 | [delegate labelViewDidClose:self]; 325 | } 326 | } 327 | 328 | -(void)moveGesture:(UIPanGestureRecognizer *)recognizer 329 | { 330 | if (!isShowingEditingHandles) { 331 | [self showEditingHandles]; 332 | } 333 | touchLocation = [recognizer locationInView:self.superview]; 334 | 335 | if (recognizer.state == UIGestureRecognizerStateBegan) { 336 | beginningPoint = touchLocation; 337 | beginningCenter = self.center; 338 | 339 | [self setCenter:[self estimatedCenter]]; 340 | beginBounds = self.bounds; 341 | 342 | if([delegate respondsToSelector:@selector(labelViewDidBeginEditing:)]) { 343 | [delegate labelViewDidBeginEditing:self]; 344 | } 345 | } else if (recognizer.state == UIGestureRecognizerStateChanged) { 346 | [self setCenter:[self estimatedCenter]]; 347 | 348 | if([delegate respondsToSelector:@selector(labelViewDidChangeEditing:)]) { 349 | [delegate labelViewDidChangeEditing:self]; 350 | } 351 | } else if (recognizer.state == UIGestureRecognizerStateEnded) { 352 | [self setCenter:[self estimatedCenter]]; 353 | 354 | if([delegate respondsToSelector:@selector(labelViewDidEndEditing:)]) { 355 | [delegate labelViewDidEndEditing:self]; 356 | } 357 | } 358 | } 359 | 360 | - (CGPoint)estimatedCenter 361 | { 362 | CGPoint newCenter; 363 | CGFloat newCenterX = beginningCenter.x + (touchLocation.x - beginningPoint.x); 364 | CGFloat newCenterY = beginningCenter.y + (touchLocation.y - beginningPoint.y); 365 | if (enableMoveRestriction) { 366 | if (!(newCenterX - 0.5 * CGRectGetWidth(self.frame) > 0 && 367 | newCenterX + 0.5 * CGRectGetWidth(self.frame) < CGRectGetWidth(self.superview.bounds))) { 368 | newCenterX = self.center.x; 369 | } 370 | if (!(newCenterY - 0.5 * CGRectGetHeight(self.frame) > 0 && 371 | newCenterY + 0.5 * CGRectGetHeight(self.frame) < CGRectGetHeight(self.superview.bounds))) { 372 | newCenterY = self.center.y; 373 | } 374 | newCenter = CGPointMake(newCenterX, newCenterY); 375 | } else { 376 | newCenter = CGPointMake(newCenterX, newCenterY); 377 | } 378 | return newCenter; 379 | } 380 | 381 | - (void)rotateViewPanGesture:(UIPanGestureRecognizer *)recognizer 382 | { 383 | touchLocation = [recognizer locationInView:self.superview]; 384 | 385 | CGPoint center = CGRectGetCenter(self.frame); 386 | 387 | if ([recognizer state] == UIGestureRecognizerStateBegan) { 388 | deltaAngle = atan2(touchLocation.y-center.y, touchLocation.x-center.x)-CGAffineTransformGetAngle(self.transform); 389 | 390 | initialBounds = self.bounds; 391 | initialDistance = CGPointGetDistance(center, touchLocation); 392 | 393 | if([delegate respondsToSelector:@selector(labelViewDidBeginEditing:)]) { 394 | [delegate labelViewDidBeginEditing:self]; 395 | } 396 | } else if ([recognizer state] == UIGestureRecognizerStateChanged) { 397 | float ang = atan2(touchLocation.y-center.y, touchLocation.x-center.x); 398 | 399 | float angleDiff = deltaAngle - ang; 400 | [self setTransform:CGAffineTransformMakeRotation(-angleDiff)]; 401 | [self setNeedsDisplay]; 402 | 403 | //Finding scale between current touchPoint and previous touchPoint 404 | double scale = sqrtf(CGPointGetDistance(center, touchLocation)/initialDistance); 405 | 406 | CGRect scaleRect = CGRectScale(initialBounds, scale, scale); 407 | 408 | if (scaleRect.size.width >= (1+globalInset*2 + 20) && scaleRect.size.height >= (1+globalInset*2 + 20)) { 409 | if (fontSize < 100 || CGRectGetWidth(scaleRect) < CGRectGetWidth(self.bounds)) { 410 | [labelTextField adjustsFontSizeToFillRect:scaleRect]; 411 | [self setBounds:scaleRect]; 412 | } 413 | } 414 | 415 | if([delegate respondsToSelector:@selector(labelViewDidChangeEditing:)]) { 416 | [delegate labelViewDidChangeEditing:self]; 417 | } 418 | } else if ([recognizer state] == UIGestureRecognizerStateEnded) { 419 | if([delegate respondsToSelector:@selector(labelViewDidEndEditing:)]) { 420 | [delegate labelViewDidEndEditing:self]; 421 | } 422 | } 423 | } 424 | 425 | #pragma mark - UITextField Delegate 426 | 427 | - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField 428 | { 429 | if (isShowingEditingHandles) { 430 | return YES; 431 | } 432 | [self contentTapped:nil]; 433 | return NO; 434 | } 435 | 436 | - (void)textFieldDidBeginEditing:(UITextField *)textField 437 | { 438 | if([delegate respondsToSelector:@selector(labelViewDidStartEditing:)]) { 439 | [delegate labelViewDidStartEditing:self]; 440 | } 441 | 442 | [textField adjustsWidthToFillItsContents]; 443 | } 444 | 445 | - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 446 | { 447 | if (!isShowingEditingHandles) { 448 | [self showEditingHandles]; 449 | } 450 | [textField adjustsWidthToFillItsContents]; 451 | return YES; 452 | } 453 | 454 | @end 455 | -------------------------------------------------------------------------------- /IQLabelView/UITextField+DynamicFontSize.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+DynamicFontSize.h 3 | // Created by kcandr on 16/12/14. 4 | 5 | #ifndef IQLabelView_UITextField_DynamicFontSize_h 6 | #define IQLabelView_UITextField_DynamicFontSize_h 7 | 8 | #import 9 | 10 | @interface UITextField (DynamicFontSize) 11 | 12 | /** Adjust font size to new bounds. 13 | * 14 | * @param newBounds A new bounds. 15 | */ 16 | - (void)adjustsFontSizeToFillRect:(CGRect)newBounds; 17 | 18 | /** Adjust width to new text. 19 | * 20 | */ 21 | - (void)adjustsWidthToFillItsContents; 22 | 23 | @end 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /IQLabelView/UITextField+DynamicFontSize.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+DynamicFontSize.m 3 | // Created by kcandr on 16/12/14. 4 | 5 | #import 6 | #import "UITextField+DynamicFontSize.h" 7 | #import "IQLabelView.h" 8 | 9 | @implementation UITextField (DynamicFontSize) 10 | 11 | static const NSUInteger IQLVMaximumFontSize = 101; 12 | static const NSUInteger IQLVMinimumFontSize = 9; 13 | 14 | - (void)adjustsFontSizeToFillRect:(CGRect)newBounds 15 | { 16 | NSString *text = (![self.text isEqualToString:@""] || !self.placeholder) ? self.text : self.placeholder; 17 | 18 | for (NSUInteger i = IQLVMaximumFontSize; i > IQLVMinimumFontSize; i--) { 19 | UIFont *font = [UIFont fontWithName:self.font.fontName size:(CGFloat)i]; 20 | NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text 21 | attributes:@{ NSFontAttributeName : font }]; 22 | 23 | CGRect rectSize = [attributedText boundingRectWithSize:CGSizeMake(CGRectGetWidth(newBounds)-24, CGFLOAT_MAX) 24 | options:NSStringDrawingUsesLineFragmentOrigin 25 | context:nil]; 26 | 27 | if (CGRectGetHeight(rectSize) <= CGRectGetHeight(newBounds)) { 28 | ((IQLabelView *)self.superview).fontSize = (CGFloat)i-1; 29 | break; 30 | } 31 | } 32 | } 33 | 34 | - (void)adjustsWidthToFillItsContents 35 | { 36 | NSString *text = (![self.text isEqualToString:@""] || !self.placeholder) ? self.text : self.placeholder; 37 | UIFont *font = [UIFont fontWithName:self.font.fontName size:self.font.pointSize]; 38 | NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text 39 | attributes:@{ NSFontAttributeName : font }]; 40 | 41 | CGRect rectSize = [attributedText boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGRectGetHeight(self.frame)-24) 42 | options:NSStringDrawingUsesLineFragmentOrigin 43 | context:nil]; 44 | 45 | float w1 = (ceilf(rectSize.size.width) + 24 < 50) ? self.frame.size.width : ceilf(rectSize.size.width) + 24; 46 | float h1 =(ceilf(rectSize.size.height) + 24 < 50) ? 50 : ceilf(rectSize.size.height) + 24; 47 | 48 | CGRect viewFrame = self.superview.bounds; 49 | viewFrame.size.width = w1 + 24; 50 | viewFrame.size.height = h1; 51 | self.superview.bounds = viewFrame; 52 | } 53 | 54 | @end -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8BE215731A45902C006EC5A5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BE215721A45902C006EC5A5 /* main.m */; }; 11 | 8BE215761A45902C006EC5A5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BE215751A45902C006EC5A5 /* AppDelegate.m */; }; 12 | 8BE215791A45902C006EC5A5 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BE215781A45902C006EC5A5 /* ViewController.m */; }; 13 | 8BE2157C1A45902D006EC5A5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8BE2157A1A45902C006EC5A5 /* Main.storyboard */; }; 14 | 8BE2157E1A45902D006EC5A5 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8BE2157D1A45902D006EC5A5 /* Images.xcassets */; }; 15 | 8BE215811A45902D006EC5A5 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8BE2157F1A45902D006EC5A5 /* LaunchScreen.xib */; }; 16 | 8BE2158D1A45902D006EC5A5 /* IQLabelViewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BE2158C1A45902D006EC5A5 /* IQLabelViewDemoTests.m */; }; 17 | 8BE215B81A4591D0006EC5A5 /* IQLabelView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BE215B41A4591D0006EC5A5 /* IQLabelView.m */; }; 18 | 8BE215B91A4591D0006EC5A5 /* IQLabelView.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 8BE215B51A4591D0006EC5A5 /* IQLabelView.bundle */; }; 19 | 8BE215BA1A4591D0006EC5A5 /* UITextField+DynamicFontSize.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BE215B71A4591D0006EC5A5 /* UITextField+DynamicFontSize.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | 8BE215871A45902D006EC5A5 /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = 8BE215651A45902C006EC5A5 /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = 8BE2156C1A45902C006EC5A5; 28 | remoteInfo = IQLabelViewDemo; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | 8BE2156D1A45902C006EC5A5 /* IQLabelViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = IQLabelViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 8BE215711A45902C006EC5A5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 8BE215721A45902C006EC5A5 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 36 | 8BE215741A45902C006EC5A5 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 37 | 8BE215751A45902C006EC5A5 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 38 | 8BE215771A45902C006EC5A5 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 39 | 8BE215781A45902C006EC5A5 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 40 | 8BE2157B1A45902D006EC5A5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | 8BE2157D1A45902D006EC5A5 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 42 | 8BE215801A45902D006EC5A5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 43 | 8BE215861A45902D006EC5A5 /* IQLabelViewDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = IQLabelViewDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 8BE2158B1A45902D006EC5A5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 8BE2158C1A45902D006EC5A5 /* IQLabelViewDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IQLabelViewDemoTests.m; sourceTree = ""; }; 46 | 8BE215B31A4591D0006EC5A5 /* IQLabelView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IQLabelView.h; sourceTree = ""; }; 47 | 8BE215B41A4591D0006EC5A5 /* IQLabelView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IQLabelView.m; sourceTree = ""; }; 48 | 8BE215B51A4591D0006EC5A5 /* IQLabelView.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = IQLabelView.bundle; sourceTree = ""; }; 49 | 8BE215B61A4591D0006EC5A5 /* UITextField+DynamicFontSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UITextField+DynamicFontSize.h"; sourceTree = ""; }; 50 | 8BE215B71A4591D0006EC5A5 /* UITextField+DynamicFontSize.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UITextField+DynamicFontSize.m"; sourceTree = ""; }; 51 | /* End PBXFileReference section */ 52 | 53 | /* Begin PBXFrameworksBuildPhase section */ 54 | 8BE2156A1A45902C006EC5A5 /* Frameworks */ = { 55 | isa = PBXFrameworksBuildPhase; 56 | buildActionMask = 2147483647; 57 | files = ( 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | 8BE215831A45902D006EC5A5 /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | /* End PBXFrameworksBuildPhase section */ 69 | 70 | /* Begin PBXGroup section */ 71 | 8BE215641A45902C006EC5A5 = { 72 | isa = PBXGroup; 73 | children = ( 74 | 8BE215B21A4591D0006EC5A5 /* IQLabelView */, 75 | 8BE2156F1A45902C006EC5A5 /* IQLabelViewDemo */, 76 | 8BE215891A45902D006EC5A5 /* IQLabelViewDemoTests */, 77 | 8BE2156E1A45902C006EC5A5 /* Products */, 78 | ); 79 | sourceTree = ""; 80 | }; 81 | 8BE2156E1A45902C006EC5A5 /* Products */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 8BE2156D1A45902C006EC5A5 /* IQLabelViewDemo.app */, 85 | 8BE215861A45902D006EC5A5 /* IQLabelViewDemoTests.xctest */, 86 | ); 87 | name = Products; 88 | sourceTree = ""; 89 | }; 90 | 8BE2156F1A45902C006EC5A5 /* IQLabelViewDemo */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 8BE215741A45902C006EC5A5 /* AppDelegate.h */, 94 | 8BE215751A45902C006EC5A5 /* AppDelegate.m */, 95 | 8BE215771A45902C006EC5A5 /* ViewController.h */, 96 | 8BE215781A45902C006EC5A5 /* ViewController.m */, 97 | 8BE2157A1A45902C006EC5A5 /* Main.storyboard */, 98 | 8BE2157D1A45902D006EC5A5 /* Images.xcassets */, 99 | 8BE2157F1A45902D006EC5A5 /* LaunchScreen.xib */, 100 | 8BE215701A45902C006EC5A5 /* Supporting Files */, 101 | ); 102 | path = IQLabelViewDemo; 103 | sourceTree = ""; 104 | }; 105 | 8BE215701A45902C006EC5A5 /* Supporting Files */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 8BE215711A45902C006EC5A5 /* Info.plist */, 109 | 8BE215721A45902C006EC5A5 /* main.m */, 110 | ); 111 | name = "Supporting Files"; 112 | sourceTree = ""; 113 | }; 114 | 8BE215891A45902D006EC5A5 /* IQLabelViewDemoTests */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | 8BE2158C1A45902D006EC5A5 /* IQLabelViewDemoTests.m */, 118 | 8BE2158A1A45902D006EC5A5 /* Supporting Files */, 119 | ); 120 | path = IQLabelViewDemoTests; 121 | sourceTree = SOURCE_ROOT; 122 | }; 123 | 8BE2158A1A45902D006EC5A5 /* Supporting Files */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | 8BE2158B1A45902D006EC5A5 /* Info.plist */, 127 | ); 128 | name = "Supporting Files"; 129 | sourceTree = ""; 130 | }; 131 | 8BE215B21A4591D0006EC5A5 /* IQLabelView */ = { 132 | isa = PBXGroup; 133 | children = ( 134 | 8BE215B31A4591D0006EC5A5 /* IQLabelView.h */, 135 | 8BE215B41A4591D0006EC5A5 /* IQLabelView.m */, 136 | 8BE215B51A4591D0006EC5A5 /* IQLabelView.bundle */, 137 | 8BE215B61A4591D0006EC5A5 /* UITextField+DynamicFontSize.h */, 138 | 8BE215B71A4591D0006EC5A5 /* UITextField+DynamicFontSize.m */, 139 | ); 140 | name = IQLabelView; 141 | path = ../IQLabelView; 142 | sourceTree = ""; 143 | }; 144 | /* End PBXGroup section */ 145 | 146 | /* Begin PBXNativeTarget section */ 147 | 8BE2156C1A45902C006EC5A5 /* IQLabelViewDemo */ = { 148 | isa = PBXNativeTarget; 149 | buildConfigurationList = 8BE215901A45902D006EC5A5 /* Build configuration list for PBXNativeTarget "IQLabelViewDemo" */; 150 | buildPhases = ( 151 | 8BE215691A45902C006EC5A5 /* Sources */, 152 | 8BE2156A1A45902C006EC5A5 /* Frameworks */, 153 | 8BE2156B1A45902C006EC5A5 /* Resources */, 154 | ); 155 | buildRules = ( 156 | ); 157 | dependencies = ( 158 | ); 159 | name = IQLabelViewDemo; 160 | productName = IQLabelViewDemo; 161 | productReference = 8BE2156D1A45902C006EC5A5 /* IQLabelViewDemo.app */; 162 | productType = "com.apple.product-type.application"; 163 | }; 164 | 8BE215851A45902D006EC5A5 /* IQLabelViewDemoTests */ = { 165 | isa = PBXNativeTarget; 166 | buildConfigurationList = 8BE215931A45902D006EC5A5 /* Build configuration list for PBXNativeTarget "IQLabelViewDemoTests" */; 167 | buildPhases = ( 168 | 8BE215821A45902D006EC5A5 /* Sources */, 169 | 8BE215831A45902D006EC5A5 /* Frameworks */, 170 | 8BE215841A45902D006EC5A5 /* Resources */, 171 | ); 172 | buildRules = ( 173 | ); 174 | dependencies = ( 175 | 8BE215881A45902D006EC5A5 /* PBXTargetDependency */, 176 | ); 177 | name = IQLabelViewDemoTests; 178 | productName = IQLabelViewDemoTests; 179 | productReference = 8BE215861A45902D006EC5A5 /* IQLabelViewDemoTests.xctest */; 180 | productType = "com.apple.product-type.bundle.unit-test"; 181 | }; 182 | /* End PBXNativeTarget section */ 183 | 184 | /* Begin PBXProject section */ 185 | 8BE215651A45902C006EC5A5 /* Project object */ = { 186 | isa = PBXProject; 187 | attributes = { 188 | LastUpgradeCheck = 0710; 189 | TargetAttributes = { 190 | 8BE2156C1A45902C006EC5A5 = { 191 | CreatedOnToolsVersion = 6.1.1; 192 | }; 193 | 8BE215851A45902D006EC5A5 = { 194 | CreatedOnToolsVersion = 6.1.1; 195 | TestTargetID = 8BE2156C1A45902C006EC5A5; 196 | }; 197 | }; 198 | }; 199 | buildConfigurationList = 8BE215681A45902C006EC5A5 /* Build configuration list for PBXProject "IQLabelViewDemo" */; 200 | compatibilityVersion = "Xcode 3.2"; 201 | developmentRegion = English; 202 | hasScannedForEncodings = 0; 203 | knownRegions = ( 204 | en, 205 | Base, 206 | ); 207 | mainGroup = 8BE215641A45902C006EC5A5; 208 | productRefGroup = 8BE2156E1A45902C006EC5A5 /* Products */; 209 | projectDirPath = ""; 210 | projectRoot = ""; 211 | targets = ( 212 | 8BE2156C1A45902C006EC5A5 /* IQLabelViewDemo */, 213 | 8BE215851A45902D006EC5A5 /* IQLabelViewDemoTests */, 214 | ); 215 | }; 216 | /* End PBXProject section */ 217 | 218 | /* Begin PBXResourcesBuildPhase section */ 219 | 8BE2156B1A45902C006EC5A5 /* Resources */ = { 220 | isa = PBXResourcesBuildPhase; 221 | buildActionMask = 2147483647; 222 | files = ( 223 | 8BE2157C1A45902D006EC5A5 /* Main.storyboard in Resources */, 224 | 8BE215811A45902D006EC5A5 /* LaunchScreen.xib in Resources */, 225 | 8BE2157E1A45902D006EC5A5 /* Images.xcassets in Resources */, 226 | 8BE215B91A4591D0006EC5A5 /* IQLabelView.bundle in Resources */, 227 | ); 228 | runOnlyForDeploymentPostprocessing = 0; 229 | }; 230 | 8BE215841A45902D006EC5A5 /* Resources */ = { 231 | isa = PBXResourcesBuildPhase; 232 | buildActionMask = 2147483647; 233 | files = ( 234 | ); 235 | runOnlyForDeploymentPostprocessing = 0; 236 | }; 237 | /* End PBXResourcesBuildPhase section */ 238 | 239 | /* Begin PBXSourcesBuildPhase section */ 240 | 8BE215691A45902C006EC5A5 /* Sources */ = { 241 | isa = PBXSourcesBuildPhase; 242 | buildActionMask = 2147483647; 243 | files = ( 244 | 8BE215BA1A4591D0006EC5A5 /* UITextField+DynamicFontSize.m in Sources */, 245 | 8BE215791A45902C006EC5A5 /* ViewController.m in Sources */, 246 | 8BE215B81A4591D0006EC5A5 /* IQLabelView.m in Sources */, 247 | 8BE215761A45902C006EC5A5 /* AppDelegate.m in Sources */, 248 | 8BE215731A45902C006EC5A5 /* main.m in Sources */, 249 | ); 250 | runOnlyForDeploymentPostprocessing = 0; 251 | }; 252 | 8BE215821A45902D006EC5A5 /* Sources */ = { 253 | isa = PBXSourcesBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | 8BE2158D1A45902D006EC5A5 /* IQLabelViewDemoTests.m in Sources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | /* End PBXSourcesBuildPhase section */ 261 | 262 | /* Begin PBXTargetDependency section */ 263 | 8BE215881A45902D006EC5A5 /* PBXTargetDependency */ = { 264 | isa = PBXTargetDependency; 265 | target = 8BE2156C1A45902C006EC5A5 /* IQLabelViewDemo */; 266 | targetProxy = 8BE215871A45902D006EC5A5 /* PBXContainerItemProxy */; 267 | }; 268 | /* End PBXTargetDependency section */ 269 | 270 | /* Begin PBXVariantGroup section */ 271 | 8BE2157A1A45902C006EC5A5 /* Main.storyboard */ = { 272 | isa = PBXVariantGroup; 273 | children = ( 274 | 8BE2157B1A45902D006EC5A5 /* Base */, 275 | ); 276 | name = Main.storyboard; 277 | sourceTree = ""; 278 | }; 279 | 8BE2157F1A45902D006EC5A5 /* LaunchScreen.xib */ = { 280 | isa = PBXVariantGroup; 281 | children = ( 282 | 8BE215801A45902D006EC5A5 /* Base */, 283 | ); 284 | name = LaunchScreen.xib; 285 | sourceTree = ""; 286 | }; 287 | /* End PBXVariantGroup section */ 288 | 289 | /* Begin XCBuildConfiguration section */ 290 | 8BE2158E1A45902D006EC5A5 /* Debug */ = { 291 | isa = XCBuildConfiguration; 292 | buildSettings = { 293 | ALWAYS_SEARCH_USER_PATHS = NO; 294 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 295 | CLANG_CXX_LIBRARY = "libc++"; 296 | CLANG_ENABLE_MODULES = YES; 297 | CLANG_ENABLE_OBJC_ARC = YES; 298 | CLANG_WARN_BOOL_CONVERSION = YES; 299 | CLANG_WARN_CONSTANT_CONVERSION = YES; 300 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 301 | CLANG_WARN_EMPTY_BODY = YES; 302 | CLANG_WARN_ENUM_CONVERSION = YES; 303 | CLANG_WARN_INT_CONVERSION = YES; 304 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 305 | CLANG_WARN_UNREACHABLE_CODE = YES; 306 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 307 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 308 | COPY_PHASE_STRIP = NO; 309 | ENABLE_STRICT_OBJC_MSGSEND = YES; 310 | ENABLE_TESTABILITY = YES; 311 | GCC_C_LANGUAGE_STANDARD = gnu99; 312 | GCC_DYNAMIC_NO_PIC = NO; 313 | GCC_OPTIMIZATION_LEVEL = 0; 314 | GCC_PREPROCESSOR_DEFINITIONS = ( 315 | "DEBUG=1", 316 | "$(inherited)", 317 | ); 318 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 319 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 320 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 321 | GCC_WARN_UNDECLARED_SELECTOR = YES; 322 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 323 | GCC_WARN_UNUSED_FUNCTION = YES; 324 | GCC_WARN_UNUSED_VARIABLE = YES; 325 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 326 | MTL_ENABLE_DEBUG_INFO = YES; 327 | ONLY_ACTIVE_ARCH = YES; 328 | SDKROOT = iphoneos; 329 | }; 330 | name = Debug; 331 | }; 332 | 8BE2158F1A45902D006EC5A5 /* Release */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | ALWAYS_SEARCH_USER_PATHS = NO; 336 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 337 | CLANG_CXX_LIBRARY = "libc++"; 338 | CLANG_ENABLE_MODULES = YES; 339 | CLANG_ENABLE_OBJC_ARC = YES; 340 | CLANG_WARN_BOOL_CONVERSION = YES; 341 | CLANG_WARN_CONSTANT_CONVERSION = YES; 342 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 343 | CLANG_WARN_EMPTY_BODY = YES; 344 | CLANG_WARN_ENUM_CONVERSION = YES; 345 | CLANG_WARN_INT_CONVERSION = YES; 346 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 347 | CLANG_WARN_UNREACHABLE_CODE = YES; 348 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 349 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 350 | COPY_PHASE_STRIP = YES; 351 | ENABLE_NS_ASSERTIONS = NO; 352 | ENABLE_STRICT_OBJC_MSGSEND = YES; 353 | GCC_C_LANGUAGE_STANDARD = gnu99; 354 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 355 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 356 | GCC_WARN_UNDECLARED_SELECTOR = YES; 357 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 358 | GCC_WARN_UNUSED_FUNCTION = YES; 359 | GCC_WARN_UNUSED_VARIABLE = YES; 360 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 361 | MTL_ENABLE_DEBUG_INFO = NO; 362 | SDKROOT = iphoneos; 363 | VALIDATE_PRODUCT = YES; 364 | }; 365 | name = Release; 366 | }; 367 | 8BE215911A45902D006EC5A5 /* Debug */ = { 368 | isa = XCBuildConfiguration; 369 | buildSettings = { 370 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 371 | INFOPLIST_FILE = IQLabelViewDemo/Info.plist; 372 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 373 | PRODUCT_BUNDLE_IDENTIFIER = com.kcandr.IQLabelViewDemo; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | }; 376 | name = Debug; 377 | }; 378 | 8BE215921A45902D006EC5A5 /* Release */ = { 379 | isa = XCBuildConfiguration; 380 | buildSettings = { 381 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 382 | INFOPLIST_FILE = IQLabelViewDemo/Info.plist; 383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 384 | PRODUCT_BUNDLE_IDENTIFIER = com.kcandr.IQLabelViewDemo; 385 | PRODUCT_NAME = "$(TARGET_NAME)"; 386 | }; 387 | name = Release; 388 | }; 389 | 8BE215941A45902D006EC5A5 /* Debug */ = { 390 | isa = XCBuildConfiguration; 391 | buildSettings = { 392 | BUNDLE_LOADER = "$(TEST_HOST)"; 393 | FRAMEWORK_SEARCH_PATHS = ( 394 | "$(SDKROOT)/Developer/Library/Frameworks", 395 | "$(inherited)", 396 | ); 397 | GCC_PREPROCESSOR_DEFINITIONS = ( 398 | "DEBUG=1", 399 | "$(inherited)", 400 | ); 401 | INFOPLIST_FILE = IQLabelViewDemoTests/Info.plist; 402 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 403 | PRODUCT_BUNDLE_IDENTIFIER = "com.kcandrr.$(PRODUCT_NAME:rfc1034identifier)"; 404 | PRODUCT_NAME = "$(TARGET_NAME)"; 405 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/IQLabelViewDemo.app/IQLabelViewDemo"; 406 | }; 407 | name = Debug; 408 | }; 409 | 8BE215951A45902D006EC5A5 /* Release */ = { 410 | isa = XCBuildConfiguration; 411 | buildSettings = { 412 | BUNDLE_LOADER = "$(TEST_HOST)"; 413 | FRAMEWORK_SEARCH_PATHS = ( 414 | "$(SDKROOT)/Developer/Library/Frameworks", 415 | "$(inherited)", 416 | ); 417 | INFOPLIST_FILE = IQLabelViewDemoTests/Info.plist; 418 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 419 | PRODUCT_BUNDLE_IDENTIFIER = "com.kcandrr.$(PRODUCT_NAME:rfc1034identifier)"; 420 | PRODUCT_NAME = "$(TARGET_NAME)"; 421 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/IQLabelViewDemo.app/IQLabelViewDemo"; 422 | }; 423 | name = Release; 424 | }; 425 | /* End XCBuildConfiguration section */ 426 | 427 | /* Begin XCConfigurationList section */ 428 | 8BE215681A45902C006EC5A5 /* Build configuration list for PBXProject "IQLabelViewDemo" */ = { 429 | isa = XCConfigurationList; 430 | buildConfigurations = ( 431 | 8BE2158E1A45902D006EC5A5 /* Debug */, 432 | 8BE2158F1A45902D006EC5A5 /* Release */, 433 | ); 434 | defaultConfigurationIsVisible = 0; 435 | defaultConfigurationName = Release; 436 | }; 437 | 8BE215901A45902D006EC5A5 /* Build configuration list for PBXNativeTarget "IQLabelViewDemo" */ = { 438 | isa = XCConfigurationList; 439 | buildConfigurations = ( 440 | 8BE215911A45902D006EC5A5 /* Debug */, 441 | 8BE215921A45902D006EC5A5 /* Release */, 442 | ); 443 | defaultConfigurationIsVisible = 0; 444 | defaultConfigurationName = Release; 445 | }; 446 | 8BE215931A45902D006EC5A5 /* Build configuration list for PBXNativeTarget "IQLabelViewDemoTests" */ = { 447 | isa = XCConfigurationList; 448 | buildConfigurations = ( 449 | 8BE215941A45902D006EC5A5 /* Debug */, 450 | 8BE215951A45902D006EC5A5 /* Release */, 451 | ); 452 | defaultConfigurationIsVisible = 0; 453 | defaultConfigurationName = Release; 454 | }; 455 | /* End XCConfigurationList section */ 456 | }; 457 | rootObject = 8BE215651A45902C006EC5A5 /* Project object */; 458 | } 459 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // IQLabelViewDemo 4 | // 5 | // Created by kcandr on 20.12.14. 6 | 7 | #import 8 | 9 | @interface AppDelegate : UIResponder 10 | 11 | @property (strong, nonatomic) UIWindow *window; 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // IQLabelViewDemo 4 | // 5 | // Created by kcandr on 20.12.14. 6 | 7 | #import "AppDelegate.h" 8 | 9 | @interface AppDelegate () 10 | 11 | @end 12 | 13 | @implementation AppDelegate 14 | 15 | 16 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 17 | // Override point for customization after application launch. 18 | return YES; 19 | } 20 | 21 | - (void)applicationWillResignActive:(UIApplication *)application { 22 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 23 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 24 | } 25 | 26 | - (void)applicationDidEnterBackground:(UIApplication *)application { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application { 32 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 33 | } 34 | 35 | - (void)applicationDidBecomeActive:(UIApplication *)application { 36 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 37 | } 38 | 39 | - (void)applicationWillTerminate:(UIApplication *)application { 40 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 41 | } 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/Images.xcassets/image.imageset/10808642_854802211228961_1051550445_n.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kcandr/IQLabelView/2fa7a1aaee68483c7b3991dd9b9d62ed89eab0d4/IQLabelViewDemo/IQLabelViewDemo/Images.xcassets/image.imageset/10808642_854802211228961_1051550445_n.jpg -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/Images.xcassets/image.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x", 6 | "filename" : "10808642_854802211228961_1051550445_n.jpg" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // IQLabelViewDemo 4 | // 5 | // Created by kcandr on 20.12.14. 6 | 7 | #import 8 | 9 | @interface ViewController : UIViewController 10 | 11 | 12 | @end 13 | 14 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // IQLabelViewDemo 4 | // 5 | // Created by kcandr on 20.12.14. 6 | 7 | #import "ViewController.h" 8 | #import "IQLabelView.h" 9 | 10 | @interface ViewController () 11 | { 12 | IQLabelView *currentlyEditingLabel; 13 | NSMutableArray *labels; 14 | } 15 | 16 | @property (nonatomic, weak) IBOutlet UIImageView *imageView; 17 | @property (nonatomic, strong) NSArray *colors; 18 | 19 | @end 20 | 21 | @implementation ViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | 26 | self.colors = [NSArray arrayWithObjects:[UIColor whiteColor], [UIColor redColor], [UIColor blueColor], nil]; 27 | 28 | UIBarButtonItem *addLabelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 29 | target:self action:@selector(addLabel)]; 30 | 31 | UIBarButtonItem *refreshColorButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh 32 | target:self action:@selector(changeColor)]; 33 | UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave 34 | target:self action:@selector(saveImage)]; 35 | self.navigationItem.leftBarButtonItem = addLabelButton; 36 | self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:saveButton, refreshColorButton, nil]; 37 | 38 | [self.view setBackgroundColor:[UIColor colorWithRed:88/255.0 green:173/255.0 blue:227/255.0 alpha:1.0]]; 39 | [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchOutside:)]]; 40 | [self.imageView setImage:[UIImage imageNamed:@"image"]]; 41 | } 42 | 43 | - (void)didReceiveMemoryWarning { 44 | [super didReceiveMemoryWarning]; 45 | // Dispose of any resources that can be recreated. 46 | } 47 | 48 | - (void)addLabel 49 | { 50 | [currentlyEditingLabel hideEditingHandles]; 51 | CGRect labelFrame = CGRectMake(CGRectGetMidX(self.imageView.frame) - arc4random() % 20, 52 | CGRectGetMidY(self.imageView.frame) - arc4random() % 20, 53 | 60, 50); 54 | 55 | IQLabelView *labelView = [[IQLabelView alloc] initWithFrame:labelFrame]; 56 | [labelView setDelegate:self]; 57 | [labelView setShowsContentShadow:NO]; 58 | [labelView setEnableMoveRestriction:YES]; 59 | [labelView setFontName:@"Baskerville-BoldItalic"]; 60 | [labelView setFontSize:21.0]; 61 | 62 | [self.imageView addSubview:labelView]; 63 | [self.imageView setUserInteractionEnabled:YES]; 64 | 65 | if (arc4random() % 2 == 0) { 66 | [labelView setAttributedPlaceholder:[[NSAttributedString alloc] 67 | initWithString:NSLocalizedString(@"Placeholder", nil) 68 | attributes:@{ NSForegroundColorAttributeName : [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.75] }]]; 69 | } 70 | 71 | currentlyEditingLabel = labelView; 72 | [labels addObject:labelView]; 73 | } 74 | 75 | - (void)saveImage 76 | { 77 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ 78 | UIImageWriteToSavedPhotosAlbum([self visibleImage], nil, nil, nil); 79 | dispatch_async(dispatch_get_main_queue(), ^{ 80 | NSLog(@"Saved to Photo Roll"); 81 | }); 82 | }); 83 | } 84 | 85 | - (void)changeColor 86 | { 87 | [currentlyEditingLabel setTextColor:[self.colors objectAtIndex:arc4random() % 3]]; 88 | } 89 | 90 | - (UIImage *)visibleImage 91 | { 92 | UIGraphicsBeginImageContextWithOptions(self.imageView.bounds.size, YES, [UIScreen mainScreen].scale); 93 | CGContextTranslateCTM(UIGraphicsGetCurrentContext(), CGRectGetMinX(self.imageView.frame), -CGRectGetMinY(self.imageView.frame)); 94 | [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 95 | UIImage *visibleViewImage = UIGraphicsGetImageFromCurrentImageContext(); 96 | UIGraphicsEndImageContext(); 97 | return visibleViewImage; 98 | } 99 | 100 | #pragma mark - Gesture 101 | 102 | - (void)touchOutside:(UITapGestureRecognizer *)touchGesture 103 | { 104 | [currentlyEditingLabel hideEditingHandles]; 105 | } 106 | 107 | #pragma mark - IQLabelDelegate 108 | 109 | - (void)labelViewDidClose:(IQLabelView *)label 110 | { 111 | // some actions after delete label 112 | [labels removeObject:label]; 113 | } 114 | 115 | - (void)labelViewDidBeginEditing:(IQLabelView *)label 116 | { 117 | // move or rotate begin 118 | } 119 | 120 | - (void)labelViewDidShowEditingHandles:(IQLabelView *)label 121 | { 122 | // showing border and control buttons 123 | currentlyEditingLabel = label; 124 | } 125 | 126 | - (void)labelViewDidHideEditingHandles:(IQLabelView *)label 127 | { 128 | // hiding border and control buttons 129 | currentlyEditingLabel = nil; 130 | } 131 | 132 | - (void)labelViewDidStartEditing:(IQLabelView *)label 133 | { 134 | // tap in text field and keyboard showing 135 | currentlyEditingLabel = label; 136 | } 137 | 138 | @end 139 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // IQLabelViewDemo 4 | // 5 | // Created by kcandr on 20.12.14. 6 | 7 | #import 8 | #import "AppDelegate.h" 9 | 10 | int main(int argc, char * argv[]) { 11 | @autoreleasepool { 12 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemoTests/IQLabelViewDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // IQLabelViewDemoTests.m 3 | // IQLabelViewDemoTests 4 | // 5 | // Created by kcandr on 20.12.14. 6 | 7 | #import 8 | #import 9 | 10 | @interface IQLabelViewDemoTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation IQLabelViewDemoTests 15 | 16 | - (void)setUp { 17 | [super setUp]; 18 | // Put setup code here. This method is called before the invocation of each test method in the class. 19 | } 20 | 21 | - (void)tearDown { 22 | // Put teardown code here. This method is called after the invocation of each test method in the class. 23 | [super tearDown]; 24 | } 25 | 26 | - (void)testExample { 27 | // This is an example of a functional test case. 28 | XCTAssert(YES, @"Pass"); 29 | } 30 | 31 | - (void)testPerformanceExample { 32 | // This is an example of a performance test case. 33 | [self measureBlock:^{ 34 | // Put the code you want to measure the time of here. 35 | }]; 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /IQLabelViewDemo/IQLabelViewDemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Alexander Romanchev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IQLabelView 2 | 3 | IQLabelView is used to add text overlay and resize and rotate it with single finger. 4 | 5 | ![IQLabelView screenshot](https://cloud.githubusercontent.com/assets/1710081/6282634/3fc18b22-b8e9-11e4-894f-6ed06e1c322c.png) ![IQLabelView screenshot](https://cloud.githubusercontent.com/assets/1710081/6490467/94a84ffe-c2b7-11e4-8cf4-05c011e26289.png) 6 | 7 | ## How to install it? 8 | 9 | [CocoaPods](http://cocoapods.org) is the easiest way to install IQLabelView. Run ```pod search IQLabelView``` to search for the latest version. Then, copy and paste the ```pod``` line to your ```Podfile```. Your podfile should look like: 10 | 11 | ``` 12 | platform :ios, '7.0' 13 | pod 'IQLabelView', '~> X.Y.Z' 14 | ``` 15 | 16 | Finally, install it by running ```pod install```. 17 | 18 | If you don't use CocoaPods, just import IQLabelView/ folder with all the .m, .h, and .bundle files to your project. 19 | 20 | ## How to use it? 21 | 22 | ### IQLabelView Class 23 | 24 | ```objective-c 25 | 26 | @interface IQLabelView : UIView 27 | 28 | /** 29 | * Text color. 30 | * 31 | * Default: white color. 32 | */ 33 | @property (nonatomic, strong) UIColor *textColor; 34 | 35 | /** 36 | * Border stroke color. 37 | * 38 | * Default: red color. 39 | */ 40 | @property (nonatomic, strong) UIColor *borderColor; 41 | 42 | /** 43 | * Name of text field font. 44 | * 45 | * Default: current system font 46 | */ 47 | @property (nonatomic, copy) NSString *fontName; 48 | 49 | /** 50 | * Size of text field font. 51 | */ 52 | @property (nonatomic, assign) CGFloat fontSize; 53 | 54 | /** 55 | * Image for close button. 56 | * 57 | * Default: sticker_close.png from IQLabelView.bundle. 58 | */ 59 | @property (nonatomic, strong) UIImage *closeImage; 60 | 61 | /** 62 | * Image for rotation button. 63 | * 64 | * Default: sticker_resize.png from IQLabelView.bundle. 65 | */ 66 | @property (nonatomic, strong) UIImage *rotateImage; 67 | 68 | /** 69 | * Placeholder. 70 | * 71 | * Default: nil 72 | */ 73 | @property (nonatomic, copy) NSAttributedString *attributedPlaceholder; 74 | 75 | /* 76 | * Base delegate protocols. 77 | */ 78 | @property (nonatomic, weak) id delegate; 79 | 80 | /** 81 | * Shows content shadow. 82 | * 83 | * Default: YES. 84 | */ 85 | @property (nonatomic) BOOL showsContentShadow; 86 | 87 | /** 88 | * Shows close button. 89 | * 90 | * Default: YES. 91 | */ 92 | @property (nonatomic, getter=isEnableClose) BOOL enableClose; 93 | 94 | /** 95 | * Shows rotate/resize butoon. 96 | * 97 | * Default: YES. 98 | */ 99 | @property (nonatomic, getter=isEnableRotate) BOOL enableRotate; 100 | 101 | /** 102 | * Resticts movements in superview bounds. 103 | * 104 | * Default: NO. 105 | */ 106 | @property (nonatomic, getter=isEnableMoveRestriction) BOOL enableMoveRestriction; 107 | 108 | /** 109 | * Hides border and control buttons. 110 | */ 111 | - (void)hideEditingHandles; 112 | 113 | /** 114 | * Shows border and control buttons. 115 | */ 116 | - (void)showEditingHandles; 117 | 118 | /** Sets the text alpha. 119 | * 120 | * @param alpha A value of text transparency. 121 | */ 122 | - (void)setTextAlpha:(CGFloat)alpha; 123 | 124 | /** Returns text alpha. 125 | * 126 | * @return A value of text transparency. 127 | */ 128 | - (CGFloat)textAlpha; 129 | 130 | @end 131 | ``` 132 | 133 | ### IQLabelViewDelegate Protocol 134 | 135 | ```objective-c 136 | @protocol IQLabelViewDelegate 137 | 138 | @optional 139 | 140 | /** 141 | * Occurs when a touch gesture event occurs on close button. 142 | * 143 | * @param label A label object informing the delegate about action. 144 | */ 145 | - (void)labelViewDidClose:(IQLabelView *)label; 146 | 147 | /** 148 | * Occurs when border and control buttons was shown. 149 | * 150 | * @param label A label object informing the delegate about showing. 151 | */ 152 | - (void)labelViewDidShowEditingHandles:(IQLabelView *)label; 153 | 154 | /** 155 | * Occurs when border and control buttons was hidden. 156 | * 157 | * @param label A label object informing the delegate about hiding. 158 | */ 159 | - (void)labelViewDidHideEditingHandles:(IQLabelView *)label; 160 | 161 | /** 162 | * Occurs when label become first responder. 163 | * 164 | * @param label A label object informing the delegate about action. 165 | */ 166 | - (void)labelViewDidStartEditing:(IQLabelView *)label; 167 | 168 | /** 169 | * Occurs when label starts move or rotate. 170 | * 171 | * @param label A label object informing the delegate about action. 172 | */ 173 | - (void)labelViewDidBeginEditing:(IQLabelView *)label; 174 | 175 | /** 176 | * Occurs when label continues move or rotate. 177 | * 178 | * @param label A label object informing the delegate about action. 179 | */ 180 | - (void)labelViewDidChangeEditing:(IQLabelView *)label; 181 | 182 | /** 183 | * Occurs when label ends move or rotate. 184 | * 185 | * @param label A label object informing the delegate about action. 186 | */ 187 | - (void)labelViewDidEndEditing:(IQLabelView *)label; 188 | 189 | @end 190 | ``` 191 | 192 | ### Example 193 | 194 | ```objective-c 195 | - (void)viewDidLoad 196 | { 197 | [super viewDidLoad]; 198 | 199 | CGRect labelFrame = CGRectMake(100, 100, 60, 50); 200 | 201 | IQLabelView *labelView = [[IQLabelView alloc] initWithFrame:labelFrame]; 202 | [labelView setDelegate:self]; 203 | [labelView setShowsContentShadow:NO]; 204 | [labelView setFontName:@"Baskerville-BoldItalic"]; 205 | [labelView setFontSize:21.0]; 206 | [labelView setAttributedPlaceholder:[[NSAttributedString alloc] initWithString:NSLocalizedString(@"Placeholder", nil) attributes:@{ NSForegroundColorAttributeName : [UIColor redColor] }]]; 207 | 208 | [self.view addSubview:labelView]; 209 | } 210 | ``` 211 | 212 | ## Reference 213 | 214 | Inspired by 215 | 216 | - [IQStickerView](https://github.com/hackiftekhar/IQStickerView) 217 | - [ZDStickerView](https://github.com/zedoul/ZDStickerView) 218 | - [SPUserResizableView](https://github.com/spoletto/SPUserResizableView) 219 | 220 | ## License 221 | 222 | The MIT License (MIT) 223 | Copyright (c) 2014 Alexander Romanchev 224 | --------------------------------------------------------------------------------