One, cut a corner of the UIView is a rounded corner
If you need to have all of the 4 corners of the UIView rounded, it is fairly straightforward to set the Cornerradius property of its layer (the project needs to use the Quartzcore framework). What do you do if you want to specify a few corners (less than 4) for rounded corners and nothing else?
In fact, it is very simple, use Uibezierpath, set Cashapelayer, set the mask effect to UIView.
// icon upper left, left bottom tangent round uibezierpath * Phoneiconpath = [Uibezierpath bezierPathWithRoundedRect:self.phoneBGView.bounds byroundingcorners: Uirectcornertopleft | Uirectcornerbottomleft Cornerradii:cgsizemake (5 , 5 *phoneiconlayer = [[Cashapelayer alloc] init];p honeiconlayer.frame = Self.phonebgview.bounds;phoneiconlayer.path = phoneiconpath.cgpath;self.phonebgview.layer.mask = Phoneiconlayer;
// The above code is very simple, the enumeration values are listed here, can be added according to the typedef ns_options (Nsuinteger, Uirectcorner) { uirectcornertopleft 10, uirectcornertopright 1 1 , Uirectcornerbottomleft 12, 13, uirectcornerallcorners = ~0UL};
Ii. changing the transparency of UIView
1. If a view has child controls on it, the transparency of the child controls changes as the alpha of the view changes;
2, if the view is Uitextfield, its alpha changes, its placeholder color and textcolor will change;
Requirement: Change the view transparency, how to keep the others intact?
Answer: This time, do not change the alpha, will affect the other controls, only need to set the background color transparency.
// by changing the transparency of the background color, there is no effect on other controls and properties Self.pswTF.backgroundColor = [Uicolor colorwithwhite:1 Alpha:0.3 ];
3, how to change the color of Uitextfield placeholder?
It's too simple to change through runtime and KVC:
// text box change placeholder color [SELF.USERNAMETF Setvalue:[uicolor Graycolor] Forkeypath:@ "_placeholderlabel.textcolor" ];
Three, when the button click, there will be a highlight effect, how to cancel it?
Look at the diagram below, it's too easy, and it's not on the code anymore.
1, the button of the type changed to custom;
2, do not tick highlighted adjusts Image.
Iv. How to add underline to the text of the button?
Idea: A custom control that is underlined titlelabel the button's child controls. Then set the class of the button in storyboard to the custom class, adding a line color.
#import <UIKit/UIKit.h>ib_designable@interface ktbutton:uibutton// the underline color below the text @property (nonatomic,strong) ibinspectable Uicolor *linecolor; @end
#import "KTButton.h"@implementationKtbutton- (ID) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {}returnSelf ;}-(void) SetColor: (Uicolor *) color{_linecolor=[color copy]; [Self setneedsdisplay];}- (void) DrawRect: (cgrect) rect {cgrect Textrect=Self.titleLabel.frame; Cgcontextref Contextref=Uigraphicsgetcurrentcontext (); CGFloat Descender=Self.titleLabel.font.descender; if([_linecolor Iskindofclass:[uicolorclass]]) {Cgcontextsetstrokecolorwithcolor (contextref, _linecolor.cgcolor); } cgcontextmovetopoint (Contextref, textrect.origin.x, TEXTRECT.ORIGIN.Y+ textRect.size.height + descender +1+2); Cgcontextaddlinetopoint (Contextref, textrect.origin.x+ textRect.size.width, TEXTRECT.ORIGIN.Y + textRect.size.height + descender +1+2); Cgcontextclosepath (CONTEXTREF); Cgcontextdrawpath (Contextref, Kcgpathstroke);}@end
ui-tangent fillet, transparency, Cancel button Click Highlight, button text underlined