前面几节讲了图片上画线
这一节 我们简单讲一讲 给图片上添加文字的方法 我们继续使用上节的代码(代码下载地址见上节末尾 http://blog.csdn.net/lwjok2007/article/details/50887396)
首先我们将添加文字的View单独抽象出现实现
创建一个类 继承自UIView
起名: AddText
定义一个协议 当输入完成之后 将内容返回给ViewController
#import <UIKit/UIKit.h>
@protocol EditTextDelegate <NSObject>
-(void)ADDTextWithText:(NSString *)TEXT;
@end
@interface AddText : UIView
@property(nonatomic,strong)id<EditTextDelegate>delegate;
@end
实现AddText
#import "AddText.h"
@implementation AddText
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.userInteractionEnabled = YES;
self.backgroundColor = [UIColor whiteColor];
[self initUserInterface];
}
return self;
}
//添加控件
- (void)initUserInterface{
//取消按钮
UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
btnCancel.frame = CGRectMake(5, 5, 60, 30);
[btnCancel setTitleColor:[UIColor blackColor] forState:UIControlStateN