UI-corner cutting, transparency, highlighted Button clicking, button text underlined, ui-circle cutting
1. Switch a corner of UIView to a rounded corner.
If you want to set all the four corners of the UIView to rounded corners, the procedure is quite simple. You only need to set the cornerRadius attribute of the Layer (the QuartzCore framework is required for the project ). If you want to specify a few corners (less than 4) as the rounded corner while others remain unchanged, what should we do?
In fact, it is very easy to use UIBezierPath, set CAShapeLayer, and set the mask effect for the UIView.
// UIBezierPath * phoneIconPath = [UIBezierPath bezierPathWithRoundedRect: self. phoneBGView. bounds byRoundingCorners: UIRectCornerTopLeft | export cornerRadii: CGSizeMake (5, 5)]; CAShapeLayer * phoneIconLayer = [[CAShapeLayer alloc] init]; phoneIconLayer. frame = self. phoneBGView. bounds; phoneIconLayer. path = phoneIconPath. CGPath; self. phoneBGView. layer. mask = phoneIconLayer;
// The code above is very simple. The enumerated values listed here can be added as needed. typedef NS_OPTIONS (NSUInteger, UIRectCorner) {UIRectCornerTopLeft = 1 <0, UIRectCornerTopRight = 1 <1, UIRectCornerBottomLeft = 1 <2, UIRectCornerBottomRight = 1 <3, UIRectCornerAllCorners = ~ 0UL };
Ii. Change the transparency of UIView
1. If a View has a sub-control, the transparency of the sub-control will also change when the alpha of the View is changed;
2. If the View is UITextField and its alpha changes, the color and textColor of its placeHolder will change;
Requirement: to change the View transparency, how to keep others as they are?
A: At this time, do not change alpha any more. It will affect other controls. You only need to set the transparency of the background color.
// By changing the transparency of the background color, other controls and attributes such as self. pswTF. backgroundColor = [UIColor colorWithWhite: 1 alpha: 0.3] are not affected.
3. How to change the placeHolder color of UITextField?
It is too simple to change through runtime and KVC:
// Change the placeHolder color in the text box [self. userNameTF setValue: [UIColor grayColor] forKeyPath: @ "_ placeholderLabel. textColor"];
3. When a button is clicked, it will have a highlighted effect. How can this problem be canceled?
It's too easy to look at the figure below. The code is no longer available here.
1. Change the Type of the Button to Custom;
2. Do not check Highlighted Adjusts Image.
4. How can I underline the text of a button?
Idea: custom control, which is underlined under titleLabel of the child control of the Button. In StoryBoard, set the Class of the Button as the custom Class and add the line color.
# Import <UIKit/UIKit. h> IB_DESIGNABLE @ interface KTButton: The underline color under UIButton // text @ property (nonatomic, strong) IBInspectable UIColor * lineColor; @ end
#import "KTButton.h"@implementation KTButton- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { } return self;}-(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:[UIColor class]]){ 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