To set rounded corners for various controls in Xib
@interfaceviewcontroller () @property (weak, nonatomic) iboutlet uiview *myview; @end @implementation viewcontroller-(void) viewdidload {[super viewDidLoad]; Span class= "Hljs-keyword" >self.myview.layer.maskstobounds = yes; self.myview.layer.cornerradius = 10;}
- Quickly set rounded corners with xib
- Set up with the user Defined Runtime Attributes
Identity Checker
- Detailed steps introduced
- Click the UI Control
- Click on the Identity Checker (the third button from the left) on the right side of Xcode
- Locate the Runtime Attributes property, set by Key Path and Value
- To set the fillet to the key Path:
- Layer.cornerradius, note that the type of the key corresponding to Value should be set to String
- Layer.maskstobounds, note that the type of the key corresponding to Value should be set to Boolean, yes when a checkmark appears on the right
- Note: after testing, set
UILabel 必须
the setting maskstobounds This key value pair, only then will appear the fillet effect; UIButton, UIView, Uiimageview just set Layer.cornerradius This key-value pair enables rounded corners
Xib to set the border effect for a control
-(void) viewDidLoad {[super viewdidload]; self.myview.layer.bordercolor = [uicolor redcolor]self.myview.layer.borderwidth = 2;}
- Quickly set borders with Xib
- The method used is basically the same as the one described above Xib, the only difference is the setting of key Path key value pair
- To set the border to the key Path:
- Layer.borderwidth, note that the type of the key corresponding to Value should be set to String
- Layer.bordercolor, note that the type of the key corresponding to Value should be set to Color
When we run the program with joy, you will find that the result is not as you think, the border effect does not appear, then is our method wrong?
- I don't know if you've noticed. Layer.bordercolor corresponds to a worthy type: color; You must remember that we set the color type as a
CGColor
good question on this.
- According to the above method we set the border color as a
UIColor
type, of course, it will not work ah.
- Here is a simple solution, we just need to create a classification for Calayer, the specific code is as follows:
Calayer+zzyxibbordercolor. h#import<QuartzCore/QuartzCore.h> @interface calayer ( Zzyxibbordercolor) @end calayer+zzyxibbordercolor.m #import calayer+ ZZYXibBorderColor.h " #import <uikit/uikit.h> @implementation calayer ( zzyxibbordercolor)-(void) Setbordercolorwithuicolor: (uicolor *) color{self.bordercolor = Color @end
Note that when you set the border color, you need layer.borderColorWithUIColor
to replacelayer.borderColor
Note: When we use Xib to set the fillet, border of the control, the key Path写错
system 不会报错
, but the operation will not achieve the desired effect
Wen/Nian (author of Jane's book)
Original link: http://www.jianshu.com/p/3f6a4343139e
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
iOS use Xib to set fillet, border effects for controls