iOS application development UIView to add border color and set a rounded border method

  • 2020-05-14 04:50:57
  • OfStack

UIView with border and border color

Reference library:

#import <QuartzCore/QuartzCore.h>


// Add borders and hints
        CGRect frameRect = CGRectMake(20, 90, self.window.frame.size.width-40, self.window.frame.size.height-180);
        UIView   *frameView = [[UIView alloc] initWithFrame:frameRect] ;
        frameView.layer.borderWidth = 1;
        frameView.layer.borderColor = [[UIColor whiteColor] CGColor];

Set the border of UIView to be rounded
In practical application, I always feel that things with rounded corners look better, such as button,label,image, etc. In the past, I often added an UIImageView as the background to those controls, and then made a picture with rounded corners. However, today I found a new way to look at the code

viewT.layer.cornerRadius = 10;// Set how round the rounded corner is
viewT.layer.borderWidth = 10;// Set the width of the border, of course not
viewT.layer.borderColor = [[UIColor redColor] CGColor];// Sets the color of the border
viewT.layer.masksToBounds = YES;// Set to NO try

Actually, viewT is an instance of UIView, or it could be a subclass instance of viewT.

Finally, don't forget to add the QuartzCore.framework library and include #import in your files < QuartzCore/QuartzCore.h > This sentence oh

Related articles: