簡體   English   中英

如何設置圓角和不剪輯子視圖

[英]How to set rounded corners and dont clip subview

我在圖像底部做了按鈕,上面有個小箭頭。

在此處輸入圖片說明

但是我要加圓角。 這是我的問題。 如果我添加圓角,則我的按鈕是蒙版到邊界,而箭頭是蒙版。 如果我將setMasksToBounds:NO設置為否,則按鈕不會轉彎。

+ (UIButton*)MCustomButtonSelected:(UIButton*)button andColor:(UIColor*)color shadowColor:(UIColor *)shadowColor andFontSize:(int)fontSize numberOfLines:(int)lines{

button.titleLabel.numberOfLines = lines;
UIImage * radialGradient = [Color getRadialGradientImage:button.frame.size centre:CGPointMake(0.5, 0.6) radius:1.4 startColor:color endColor:shadowColor];
[button setBackgroundColor:[UIColor colorWithPatternImage:radialGradient]];
[button.layer setBorderColor:[[UIColor clearColor] CGColor]];
button.layer.cornerRadius = 5;
[button.layer setMasksToBounds:NO];       // here is the problem 
[button.layer setOpaque:NO];
[button.titleLabel setTextAlignment:NSTextAlignmentCenter];
[button.titleLabel setFont:[UIFont fontWithName:[Fonts mainFontName] size:fontSize]];
button.titleLabel.adjustsFontSizeToFitWidth = YES;
[button.titleLabel setShadowOffset:CGSizeMake(0.5, 0.5)];
[button setTitleShadowColor:[Color buttonNormalTextShadowColor] forState:UIControlStateNormal];
[button setTitleColor:[Color buttonNormalTextColor] forState:UIControlStateNormal];
[button setTitleShadowColor:[Color buttonPressTextShadowColor] forState:UIControlStateHighlighted];
[button setTitleColor:[Color buttonPressTextColor] forState:UIControlStateHighlighted];

CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_4);
UIView * pointer = [[UIView alloc]initWithFrame:CGRectMake(button.frame.size.width/2-5, button.frame.size.height-5, 10, 10)];
pointer.backgroundColor = color;
pointer.transform = transform;
pointer.tag = 10;
pointer.clipsToBounds = NO;

[button addSubview:pointer];
[button sendSubviewToBack:pointer];
return button;
}

誰能幫我嗎。

做這個:

UIBezierPath *path = "create a path representing ur desired shape, along with the arrow"
CAShapeLayer *shape = [CAShapeLayer layer];
shape.path = path.CGPath;

button.layer.mask = shape;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM