[英]cornerRadius not working if replacing default view with custom subclass
Following setup: 以下设置:
i have a popupViewController that has a custom UIView subclass as its view, done in loadView
我有一个popupViewController,它有一个自定义的UIView子类作为其视图,在
loadView
完成
- (void)loadView
{
CGRect startingPopupSize = CGRectMake(0.0f, 0.0f, 300.0f, 160.0f);
_popupView = [[MoviePopupView alloc] initWithFrame:startingPopupSize];
self.view = _popupView;
}
in this UIView Subclass i have the following code in it's init method 在这个UIView子类中,我在它的init方法中有以下代码
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.layer.masksToBounds = YES;
self.layer.opaque = NO;
self.clipsToBounds = YES;
self.backgroundColor = [UIColor whiteColor];
self.layer.borderWidth = 1.0f;
self.layer.cornerRadius = 10.0f;
}
return self;
}
the problem is, the cornerRadius
does not work for this view, but the border gets drawn, see here: 问题是,
cornerRadius
不适用于此视图,但边框被绘制,请参见此处:
if i don't replace this view with the default uiview of the uiviewcontroller and instead add it as a subview, the cornerRadius works just fine (i want to replace it for several reasons). 如果我不使用uiviewcontroller的默认uiview替换此视图,而是将其添加为子视图,则cornerRadius工作正常(我想替换它有几个原因)。
any ideas why this is not working? 任何想法为什么这不起作用?
if i just move the layers masksToBounds = YES
property from the initWithFrame
Method to the drawRect
method it works. 如果我只是将来自
initWithFrame
方法的masksToBounds = YES
属性移动到drawRect
方法,它就可以工作。 moving it to its viewcontrollers viewDidLoad
doesn't. 将它移动到viewcontrollers
viewDidLoad
没有。
- (void)drawRect:(CGRect)rect
{
// Drawing code
self.layer.masksToBounds = YES;
}
any ideas why this works? 任何想法为什么这个工作? i think it is not the right place to set this property here.
我认为这不是在这里设置这个属性的合适地方。
You should make two views: 你应该提出两个观点:
For background view set color you want for your text background. 对于背景视图设置您想要的文本背景颜色。 For text view set background color as clear color.
对于文本视图设置背景颜色作为清晰的颜色。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.