When we draw the UI interface, we usually make the border with a layer and then add a shadow to it, I prefer to use the following method,
UI to get a few frames of picture, with code to stretch the picture
-(UIImage *) Changeborderimage: (UIImage *) borderimage {UIImage*image =Borderimage; CGFloat Top=2;//Top Cover HeightCGFloat bottom =2;//Bottom Cover HeightCGFloat left =2;//Left cover widthCGFloat right =2;//right End cover widthUiedgeinsets insets =Uiedgeinsetsmake (top, left, bottom, right); //specified as stretch mode, re-assigned after scalingImage =[Image Resizableimagewithcapinsets:insets Resizingmode:uiimageresizingmodestretch]; returnimage;}
Customize a border View or add a uiimageview with stretched uiimage underneath your view.
All code:
BorderView.h
// // BorderView.h// border_creat//// Created by Tan Qihong on 15/12/15. // copyright©2015 year Tan Qihong. All rights reserved. // #import <UIKit/UIKit.h>@interface*borderimage; -(Instancetype) initWithFrame: (CGRect) frame borderimage: (UIImage *) borderimage; @end
borderview.m
////borderview.m//border_creat////Created by Tan Qihong on 15/12/15.//copyright©2015 year Tan Qihong. All rights reserved.//#import "BorderView.h"@implementationBorderview-(Instancetype) initWithFrame: (CGRect) frame borderimage: (UIImage *) borderimage { self=[Super Initwithframe:frame]; if(self) {self.image=[self changeborderimage:borderimage]; } returnSelf ;}- (void) Setborderimage: (UIImage *) borderimage {self.borderimage=[self changeborderimage:borderimage];}-(UIImage *) Changeborderimage: (UIImage *) borderimage {UIImage*image =Borderimage; CGFloat Top=2;//Top Cover HeightCGFloat bottom =2;//Bottom Cover HeightCGFloat left =2;//Left cover widthCGFloat right =2;//right End cover widthUiedgeinsets insets =Uiedgeinsetsmake (top, left, bottom, right); //specified as stretch mode, re-assigned after scalingImage =[Image Resizableimagewithcapinsets:insets Resizingmode:uiimageresizingmodestretch]; returnimage;}@end
Viewcontroller.m
- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Whitecolor]; Borderview*borderview = [[Borderview alloc]initwithframe:cgrectmake ( -, -, -, -) Borderimage:[uiimage imagenamed:@"tool_biankuang2"]]; [Self.view Addsubview:borderview]; Borderview*borderview1 = [[Borderview alloc]initwithframe:cgrectmake ( -, $, Max, -) Borderimage:[uiimage imagenamed:@"tool_biankuang2"]]; [Self.view Addsubview:borderview1]; Borderview*borderview2 = [[Borderview alloc]initwithframe:cgrectmake ( -, -, -, -) Borderimage:[uiimage imagenamed:@"Tool_biankuang"]]; [Self.view Addsubview:borderview2]; }
:
A simple approach to the iOS view border