To set any rounded corners of a picture

Source: Internet
Author: User

Sometimes, when we do cell, we meet this demand.

  

requirements, the first cell and the last cell of each group in the TableView display two rounded corners

When you hear the rounded corners, it is estimated that many people will think of the following two lines of code, but can not do the above effect.

Layer.cornerradius = 10;

Layer.maskstobounds = YES;

In fact, the simplest way to make the art (UI designer) to do two of these background images, and then set up the cell Cell.backgroundview is complete, this is the quickest way, but if the UI is not given, it can only be: a word to cut the picture.

When it comes to cutting pictures, think of Cashapelayer, don't ask me why, because it has a property that is path, and then think of a method in Uibezierpath

+ (Instancetype) Bezierpathwithroundedrect: (cgrect) rect byroundingcorners: (uirectcorner) Corners cornerRadii: ( Cgsize) cornerradii;

The Uirectcorner in this method is an enumeration with the following values:

Uirectcornertopleft = 1 << 0,

Uirectcornertopright = 1 << 1,

Uirectcornerbottomleft = 1 << 2,

Uirectcornerbottomright = 1 << 3,

Uirectcornerallcorners = ~0ul

This is a lot easier, on the code:

  

In the storyboard put a uiimageview, arbitrarily set up a picture.

  

////VIEWCONTROLLER.M//Set rounded corners////Created by Hqw on 16/4/20.//copyright©2016 year cormorants. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet Uiimageview*ImageView;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Uibezierpath*path = [Uibezierpath bezierPathWithRoundedRect:self.imageView.bounds byroundingcorners:uirectcornertopleft | Uirectcornertopright Cornerradii:cgsizemake (Ten,Ten)]; Cashapelayer*layer =[Cashapelayer layer]; Layer.frame=Self.imageView.bounds; Layer.path=path.    Cgpath; Self.imageView.layer.mask=layer;}@end

The results are as follows:

  

With this picture cell's fillet demand is solved.

To set any rounded corners of a picture

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.