0

我想用占位符改进一个超酷的文本视图,并像 textField 一样添加超酷的框架。为此,您只需将此代码添加到您的awakeFromNib方法中:

- (void)awakeFromNib
{
    [super awakeFromNib];
    if (self.editable) {
        CALayer *selfLayer = self.layer;
        UIImage *stretchableImage = [UIImage imageNamed:@"TextView"];
        selfLayer.contents = (id)stretchableImage.CGImage;
        selfLayer.contentsScale = [UIScreen mainScreen].scale; // Needed for the retina display, otherwise our image will not be scaled properly.
        selfLayer.contentsCenter = CGRectMake(0.5, 0.5, 1.0/stretchableImage.size.width,1.0/stretchableImage.size.height);

        self.backgroundColor = [UIColor clearColor];
    }
}

问题是如果你把它添加if()到上面提到placeholderTextView的方法中,awakeFromNib就不会被调用!为什么 ?是因为访问此视图的图层属性吗?请指导我完成这些图形内容..!drawRectplaceholderTextView

4

0 回答 0