Ios 如何在普通UITextView上绘制Rect?
如何在普通UITextView上绘制?例如,我有一个自定义UIView类,它将cornerRadius设置为5,将背景色设置为[UIColor greenColor]Ios 如何在普通UITextView上绘制Rect?,ios,objective-c,core-graphics,Ios,Objective C,Core Graphics,如何在普通UITextView上绘制?例如,我有一个自定义UIView类,它将cornerRadius设置为5,将背景色设置为[UIColor greenColor] @implementation ChatBubbleTextView -(id) initWithCoder:(NSCoder *)aDecoder { self = [super initWithCoder:aDecoder]; if (self){ self.layer.cornerRadius
@implementation ChatBubbleTextView
-(id) initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self){
self.layer.cornerRadius = 5;
self.layer.backgroundColor = [UIColor greenColor].CGColor;
}
return self;
}
@end
但一旦我添加了drawRect方法,它就会使我的UIView为空。有没有一种方法可以同时使用普通的drawRect和我自己的drawRect实现
我也试过了
-(void)drawRect:(CGRect)rect{
[super drawRect:rect];
}
界面:
#import <UIKit/UIKit.h>
@interface ChatBubbleTextView : UITextView
@end
#导入
@接口ChatBubbleTextView:UITextView
@结束
出于某种原因,self.layer.backgroundColor=[UIColor greenColor].CGColor
将在没有drawRect的情况下工作。但是,当存在drawRect时,它将不起作用。您必须使用[self-setBackgroundColor:[UIColor-greenColor]
是否可以显示自定义类的接口。drawRect是创建自定义UITextview时的默认方法,我是否应该知道您到底想要实现什么,这个问题似乎无法理解您想要什么。?