Set the specified bounding fillet

Source: Internet
Author: User
Tags uikit

In recent projects, some of the boundaries of some views have to be set to rounded corners, such as specifying a rectangular view that needs to be rounded to the left, so encapsulate a class to achieve a rounded corner of a specified boundary

1, first create a taxonomy that inherits from UIView (because I need to set a button fillet in the project, so named BTN)

2. Setting the interface in the interface file

Here are the parameters: distance the height or width of the boundary where the fillet is to be set

#import <UIKit/UIKit.h>enum  {    zssideroundleft,    zssideroundright,    Zssideroundup,    Zssiderounddown} zssideround; @interface UIView (ZSSIDEROUNDBTN)-(void) roundside: (zssideround) side distance: (cgfloat) distance; @end

3. Implemented in. m (Specify the boundary set to semicircle here)

#import "Uiview+zssideroundbtn.h"@implementationUIView (ZSSIDEROUNDBTN)- (void) Roundside: (zssideround) side distance: (cgfloat) distance{Uibezierpath*Maskpath; if(Side = =zssideroundleft) {Maskpath=[Uibezierpath bezierPathWithRoundedRect:self.bounds byroundingcorners: (uirect Cornertopleft|uirectcornerbottomleft) cornerradii:cgsizemake (distance/2, distance/2)]; }    Else if(Side = =zssideroundright) {Maskpath=[Uibezierpath bezierPathWithRoundedRect:self.bounds byroundingcorners: (uirect Cornertopright|uirectcornerbottomright) cornerradii:cgsizemake (distance/2, distance/2)]; }    Else if(Side = =zssideroundup) {Maskpath=[Uibezierpath bezierPathWithRoundedRect:self.bounds byroundingcorners: (uirect Cornertopleft|uirectcornertopright) cornerradii:cgsizemake (distance/2, distance/2)]; }    Else{Maskpath=[Uibezierpath bezierPathWithRoundedRect:self.bounds byroundingcorners: (uirect Cornerbottomleft|uirectcornerbottomright) cornerradii:cgsizemake (distance/2, distance/2)]; }    //Create a shape layer, set its pathcashapelayer* Masklayer =[Cashapelayer layer]; Masklayer.frame=Self.bounds; Masklayer.path=Maskpath.cgpath; //The newly created shape layer is set to the mask of the image view layerSelf.layer.mask =Masklayer; [Self.layer Setmaskstobounds:yes];}@end

I need to set some UIView sub-Class View when the boundary is semicircle, the direct reference is OK

Set the specified bounding fillet

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.