قالب وردپرس درنا توس
Home / IOS Development / # 311: Round corner enhancements ✅ – Small pieces of cocoa

# 311: Round corner enhancements ✅ – Small pieces of cocoa



Subjects

Topics

Today we are talking about corners . Particularly rounded. In IOS 11, Apple has improved the way we can specify and work with the rounding of our views. Let's have a look.

Let's start with where we were before iOS 11.

Before iOS 11, a UIView was configured to have rounded corners as follows:

  la    see    =    UIView   () 

  view .   clipsToBounds    =    true 
  view .   layer . [1
9659014] cornerRadius
= 8

clipsToBounds ensures that clipping takes place and the next round rounds all four corners with a radius of 8 : [19659005] ]

Simply.

This approach works well to round all four corners of a view. But what if we wanted to around only some of the four corners? In the past, we had to let down and create our own mask layer and give it a path we created manually.

IOS 11 makes this way easier.

Measure CACornerMask !

Now we can use the same code as before, with a small addition:

  la    riss    =    UIView   () 

  display .   clipsToBounds    =    true 
  view .   layer .   corner Radius    =    8 
  view .   layer .   maskedCorners    =    [.   layerMaxXMaxYCorner    .   layerMinXMaxYCorner ] 

Now we can use the new CACornerMask option set to specify which corners we want to round. Here we have requested that only the bottom two corners be rounded with a 8 point radius:

Tidy!

Before we go, there's one last thing to know about round corners in iOS 11:

They're now completely animated! 🎉

In previous editions, this next code will not do anything but in iOS 11, this works exactly as expected:

  la    see    =    UIView   () 

  view .   clipsToBounds    =    true 
  view .   layer .   cornerRadius [19659000] =    16 [19659084] UIViewPropertyAnimator   (  duration :    1     curve .      linear )    {
    display .   layer .   corner Radius    =    0 
} .   startAnimation   () 

Very fun.


Source link