Get the App
SLTechnology News&Howtos  ›  Development  › 

Why the cornerradius property is invalid

Shulou Source: shulou.com Published: 2022-06-03 11:02:10 11月15日 Update

Xiaobian to share with you why cornerradius attributes will be invalid, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

cornerRadius attribute borderWidth Today, use the following two sentences to add rounded corners to a view, encounter two invalid cases, record as follows, when someone finds it, take less detours self.myView.layer.cornerRadius =5.0;self.myView.layer.masksToBounds = YES.

Reason for invalid cornerRadius attribute

One: When you write this method in the controller's init method, it is invalid.

Write it in the viewDidLoaded method.

2: If I didn't write the second sentence, rounded corners still couldn't be added.

Because cornerradius is valid only if masksToBounds is yes.

But masksToBounds defaults to no,

Another thing to note is that if you set some other properties, it is possible to set this maskToBounds to yes.

For example: borderWidth

The correct posture for iOS CornerRadius

The wrong way to set rounded corners in iOS will cause off-screen rendering

m.layer.cornerRadius=8

m.layer.borderColor=UIColor.redColor().CGColor

m.layer.masksToBounds=true//This sentence will be rendered off screen early, causing the screen to stutter

Current tests address UIImageView, UILabel, and UIButton cases

classCornerRadiusLayer:CALayer{

overridefuncdisplay(){

self.contentsScale=UIScreen.mainScreen().scale

super.display()

}

varsborderWidth:CGFloat?

varscornerRadius:CGFloat?

varsborderColor:UIColor?

overridefuncdrawInContext(ctx:CGContext){

The above is "why cornerradius attribute is invalid" all the content of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!

Tags: Properties rounded corners situation method time article content screen not much code reason only most posture way more knowledge industry information information channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker MariaDB Microsoft Apple