IQLabelView用于添加文本叠加,并用单指调整大小和旋转。
CocoaPods是安装IQLabelView最简单的方式。运行pod search IQLabelView
查找最新版本。然后,把pod
行复制粘贴到您的Podfile
中。
platform :ios, '7.0'
pod 'IQLabelView', '~> X.Y.Z'
最后,通过运行pod install
来安装。
如果您不使用CocoaPods,只需将包含所有.m、.h和.bundle文件的IQLabelView/文件夹导入到您的项目中。
@interface IQLabelView : UIView
/**
* Text color.
*
* Default: white color.
*/
@property (nonatomic, strong) UIColor *textColor;
/**
* Border stroke color.
*
* Default: red color.
*/
@property (nonatomic, strong) UIColor *borderColor;
/**
* Name of text field font.
*
* Default: current system font
*/
@property (nonatomic, copy) NSString *fontName;
/**
* Size of text field font.
*/
@property (nonatomic, assign) CGFloat fontSize;
/**
* Image for close button.
*
* Default: sticker_close.png from IQLabelView.bundle.
*/
@property (nonatomic, strong) UIImage *closeImage;
/**
* Image for rotation button.
*
* Default: sticker_resize.png from IQLabelView.bundle.
*/
@property (nonatomic, strong) UIImage *rotateImage;
/**
* Placeholder.
*
* Default: nil
*/
@property (nonatomic, copy) NSAttributedString *attributedPlaceholder;
/*
* Base delegate protocols.
*/
@property (nonatomic, weak) id <IQLabelViewDelegate> delegate;
/**
* Shows content shadow.
*
* Default: YES.
*/
@property (nonatomic) BOOL showsContentShadow;
/**
* Shows close button.
*
* Default: YES.
*/
@property (nonatomic, getter=isEnableClose) BOOL enableClose;
/**
* Shows rotate/resize butoon.
*
* Default: YES.
*/
@property (nonatomic, getter=isEnableRotate) BOOL enableRotate;
/**
* Resticts movements in superview bounds.
*
* Default: NO.
*/
@property (nonatomic, getter=isEnableMoveRestriction) BOOL enableMoveRestriction;
/**
* Hides border and control buttons.
*/
- (void)hideEditingHandles;
/**
* Shows border and control buttons.
*/
- (void)showEditingHandles;
/** Sets the text alpha.
*
* @param alpha A value of text transparency.
*/
- (void)setTextAlpha:(CGFloat)alpha;
/** Returns text alpha.
*
* @return A value of text transparency.
*/
- (CGFloat)textAlpha;
@end
@protocol IQLabelViewDelegate <NSObject>
@optional
/**
* Occurs when a touch gesture event occurs on close button.
*
* @param label A label object informing the delegate about action.
*/
- (void)labelViewDidClose:(IQLabelView *)label;
/**
* Occurs when border and control buttons was shown.
*
* @param label A label object informing the delegate about showing.
*/
- (void)labelViewDidShowEditingHandles:(IQLabelView *)label;
/**
* Occurs when border and control buttons was hidden.
*
* @param label A label object informing the delegate about hiding.
*/
- (void)labelViewDidHideEditingHandles:(IQLabelView *)label;
/**
* Occurs when label become first responder.
*
* @param label A label object informing the delegate about action.
*/
- (void)labelViewDidStartEditing:(IQLabelView *)label;
/**
* Occurs when label starts move or rotate.
*
* @param label A label object informing the delegate about action.
*/
- (void)labelViewDidBeginEditing:(IQLabelView *)label;
/**
* Occurs when label continues move or rotate.
*
* @param label A label object informing the delegate about action.
*/
- (void)labelViewDidChangeEditing:(IQLabelView *)label;
/**
* Occurs when label ends move or rotate.
*
* @param label A label object informing the delegate about action.
*/
- (void)labelViewDidEndEditing:(IQLabelView *)label;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect labelFrame = CGRectMake(100, 100, 60, 50);
IQLabelView *labelView = [[IQLabelView alloc] initWithFrame:labelFrame];
[labelView setDelegate:self];
[labelView setShowsContentShadow:NO];
[labelView setFontName:@"Baskerville-BoldItalic"];
[labelView setFontSize:21.0];
[labelView setAttributedPlaceholder:[[NSAttributedString alloc] initWithString:NSLocalizedString(@"Placeholder", nil) attributes:@{ NSForegroundColorAttributeName : [UIColor redColor] }]];
[self.view addSubview:labelView];
}
灵感来自
MIT许可证(MIT)版权所有 © 2014 Alexander Romanchev