Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Why the cornerradius property is invalid

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report