CornerRadius does not work if you replace the default view with a custom subclass

The following setting:

I have a popupViewController that has a custom subclass of UIView as its kind made in loadView

 - (void)loadView { CGRect startingPopupSize = CGRectMake(0.0f, 0.0f, 300.0f, 160.0f); _popupView = [[MoviePopupView alloc] initWithFrame:startingPopupSize]; self.view = _popupView; } 

in this subclass of UIView I have the following code in it the init method

 - (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 that cornerRadius does not work for this view, but the border is drawn, see here:

no cornerRadius

if I don't replace this view with uiview by default for uiviewcontroller and instead add it as a subview, cornerRadius works just fine (I want to replace it for several reasons).

any ideas why this is not working?


Edit:

If I just move the properties of the masksToBounds = YES layers from the initWithFrame method to the drawRect method, it works. move it to your controllers view viewDidLoad no.

 - (void)drawRect:(CGRect)rect { // Drawing code self.layer.masksToBounds = YES; } 

any ideas why this works? I think this is not a suitable place to set this property here.

+4
source share
1 answer

You should do two kinds:

  • background view
  • text view

For the background color specified by the color for the text. For the text view, set the background color to pure color.

+1
source

Source: https://habr.com/ru/post/1440973/


All Articles